本帖最后由 KDZ 于 2014-2-27 10:25 编辑
求:各列的并列条件同时成立:即第1列,并第2列,并第5列,并第8列,的同一内容在本列重复,并第17列为“1”,并第22列为空,并第29列为“1”时,删除所有符合上述并列条件的所有重复行,但必须保留符合上述并列条件的所有重复行中的一行的VBA数组代码,注意是数组方法!! 请高手指教,跪求!急用,谢谢!!
以下是原来没有用数组的代码,怎么转化为数组法?请帮忙! Sub 删除复行() [ Dim ROW As Integer Dim i As Integer ROW = Range("D65536").End(xlUp).Row For i = 1 To ROW For j = i + 1 To ROW If Cells(j, 1) = Cells(i, 1) And Cells(j, 2) = Cells(i, 2) And Cells(j, 5) = Cells(i, 5) And Cells(j, 8) = Cells(i, 8) And Cells(j, 17) = 1 And Cells(j, 22) = "" And Cells(j, 29) = 1 Then Range(Cells(j, 1), Cells(j, 256)).Rows.Delete j = j - 1 ROW = ROW - 1 End If Next Next
- Sub Macro1()
- Dim arr, rng As Range, d, d2, i&, x$
- Set d = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- arr = [a1:af11]
- For i = 4 To UBound(arr)
- x = arr(i, 1) & "," & arr(i, 2) & "," & arr(i, 5) & "," & arr(i, 8)
- If Not d.exists(x) Then
- d(x) = ""
- Else
- If arr(i, 17) = 1 And arr(i, 22) = "" And arr(i, 29) = 1 Then
- If Not d2.exists(x) Then
- d2(x) = ""
- Else
- If rng Is Nothing Then Set rng = Cells(i, 1) Else Set rng = Union(rng, Cells(i, 1))
- End If
- End If
- End If
- Next
- If Not rng Is Nothing Then rng.EntireRow.Delete
- End Sub
复制代码
|