|
为了测试的效果,再表格里面多增加了一行。
- Sub fyExcelVBA()
- Dim arr, brr, i%, j%, path$, str$, n%, str1$
- Dim dic As Object, dic1 As Object, dic2 As Object
- Application.DisplayAlerts = False
- Application.ScreenUpdating = False
- Set dic = CreateObject("scripting.dictionary")
- Set dic1 = CreateObject("scripting.dictionary")
- Set dic2 = CreateObject("scripting.dictionary")
- path = ThisWorkbook.path & ""
- str = "代收货款账单.xls"
- With Workbooks.Open(path & str)
- arr = .ActiveSheet.Range("a1").CurrentRegion
- .Close 0
- End With
- brr = ActiveSheet.Range("a2").CurrentRegion
- For i = 2 To UBound(brr)
- dic(brr(i, 2)) = ""
- Next i
- n = 0
- For i = 2 To UBound(arr)
- If Not dic.exists(arr(i, 1)) Then
- If Not dic1.exists(arr(i, 1)) Then
- If Not dic2.exists(arr(i, 25)) Then
- dic2(arr(i, 25)) = arr(i, 12)
- dic1(arr(i, 1)) = arr(i, 23) & "/" & arr(i, 25) & "/"
- Else
- dic2(arr(i, 25)) = dic2(arr(i, 25)) + arr(i, 12)
- dic1(arr(i, 1)) = arr(i, 23) & "/" & arr(i, 25) & "/"
- End If
- End If
- End If
- Next i
- kk = dic2.items
- With Workbooks.Open(path & str)
- .ActiveSheet.Cells.Interior.ColorIndex = 0
- For i = 2 To UBound(arr)
- If dic1.exists(arr(i, 1)) Then
- Rows(i).Interior.Color = 65535
- End If
- Next i
- .Close 1
- End With
- For i = 0 To dic2.Count - 1
- str1 = str1 & Chr(10) & dic1.items()(i) & dic2.items()(i)
- Next i
- MsgBox str1
- Set dic = Nothing: Set dic1 = Nothing: Set dic2 = Nothing
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|