- Sub QC()
- Dim dic, arr(), data, i As Long, k As Long, rs As Range, j As Long
- Set dic = CreateObject("Scripting.Dictionary")
- data = Sheet1.[A2:B7656]
- For i = LBound(data) To UBound(data)
- If Not dic.exists(data(i, 1) & "" & Abs(data(i, 2))) Then
- k = k + 1
- dic(data(i, 1) & "" & Abs(data(i, 2))) = k
- ReDim Preserve arr(1 To 2, 1 To k)
- End If
- If data(i, 2) > 0 Then
- If arr(1, dic(data(i, 1) & "" & Abs(data(i, 2)))) = "" Then
- arr(1, dic(data(i, 1) & "" & Abs(data(i, 2)))) = i + 1
- Else
- arr(1, dic(data(i, 1) & "" & Abs(data(i, 2)))) = arr(1, dic(data(i, 1) & "" & Abs(data(i, 2)))) & "," & i + 1
- End If
- Else
- If arr(2, dic(data(i, 1) & "" & Abs(data(i, 2)))) = "" Then
- arr(2, dic(data(i, 1) & "" & Abs(data(i, 2)))) = i + 1
- Else
- arr(2, dic(data(i, 1) & "" & Abs(data(i, 2)))) = arr(2, dic(data(i, 1) & "" & Abs(data(i, 2)))) & "," & i + 1
- End If
- End If
- Next i
- For i = 1 To k
- If arr(1, i) <> "" And arr(2, i) <> "" Then
- For j = 0 To WorksheetFunction.Min(UBound(Split(arr(1, i), ",")), UBound(Split(arr(2, i), ",")))
- If rs Is Nothing Then
- Set rs = Union(Rows(Split(arr(1, i), ",")(j)), Rows(Split(arr(2, i), ",")(j)))
- Else
- Set rs = Union(rs, Rows(Split(arr(1, i), ",")(j)), Rows(Split(arr(2, i), ",")(j)))
- End If
-
- Next j
- End If
- Next i
- If Not rs Is Nothing Then rs.Delete
- End Sub
复制代码 这样?只消除同一账号下金额互为正负的? |