|
今天遇到这样一道题,删除重复数据的行,由于每行数据都没有排序,刚好用到了刚学的arraylist,挺方便的。- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim rng As Range
- Dim d As Object
- Dim arrlst As Object
- Set d = CreateObject("scripting.dictionary")
- Set arrlst = CreateObject("system.collections.arraylist")
- With Worksheets("sheet1")
- arr = .Range("c4:g13")
- For i = 1 To UBound(arr)
- arrlst.Clear
- For j = 1 To UBound(arr, 2)
- arrlst.Add arr(i, j)
- Next
- arrlst.Sort
- ss = Join(arrlst.toarray, ",")
- If Not d.exists(ss) Then
- d(ss) = ""
- Else
- If rng Is Nothing Then
- Set rng = .Cells(i + 3, 3).Resize(1, UBound(arr, 2))
- Else
- Set rng = Union(rng, .Cells(i + 3, 3).Resize(1, UBound(arr, 2)))
- End If
- End If
- Next
- If Not rng Is Nothing Then
- rng.Delete shift:=xlUp
- End If
- End With
- End Sub
复制代码
|
评分
-
2
查看全部评分
-
|