來個字典法。小數點是保留6位
book1.rar
(24 KB, 下载次数: 18)
- Sub test()
- [c:x] = ""
- Dim r&, Arr, d
- Arr = [a1].CurrentRegion
- Set d = CreateObject("scripting.dictionary")
- For r = 1 To UBound(Arr)
- If Not d.exists(Arr(r, 1)) Then
- d(Arr(r, 1)) = Round(Arr(r, 2), 6)
- Else
- If Round(Arr(r, 2), 6) <> d(Arr(r, 1)) Then d(Arr(r, 1)) = d(Arr(r, 1)) & "|" & Round(Arr(r, 2), 6)
- End If
- Next
- [c1].Resize(d.Count, 2) = Application.Transpose(Array(d.keys, d.items))
- For r = 1 To d.Count
- If InStr(Cells(r, "d"), "|") > 0 Then
- Cells(r, "d").Resize(1, UBound(Split(Cells(r, "d"), "|")) + 1) = Split(Cells(r, "d"), "|")
- End If
- Next
- End Sub
复制代码 |