|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
那就参照22楼老师的代码改一下就行了- Sub qq()
- Dim d, arr, i%, j%, brr(), s1#, s2#, t
- Set d = CreateObject("Scripting.Dictionary")
- arr = [a1].CurrentRegion
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- d(arr(i, 2)) = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3) & "|" & arr(i, 4) & "|" & arr(i, 5)
- Else
- s1 = Sqr(arr(i, 3) ^ 2 + arr(i, 4) ^ 2)
- s2 = Sqr(Val(Split(d(arr(i, 2)), "|")(2)) ^ 2 + Val(Split(d(arr(i, 2)), "|")(3)) ^ 2)
- If s1 < s2 Then
- d(arr(i, 2)) = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3) & "|" & arr(i, 4) & "|" & arr(i, 5)
- End If
- End If
- Next
- t = d.items
- ReDim brr(1 To d.Count, 1 To 5)
- For i = 1 To d.Count
- For j = 1 To 5
- brr(i, j) = Split(t(i - 1), "|")(j - 1)
- Next
- Next
- Sheet2.Cells.Clear
- Sheet2.[a1].Resize(d.Count, 5) = brr
- End Sub
复制代码 |
|