以下代码,供测试:
- Sub fyExcelVba()
- Dim arr, brr, crr(), i%, j%
- Dim dic As Object
- arr = Sheets("电费台账").Range("a1").CurrentRegion
- brr = Sheets("报账数据").Range("a1").CurrentRegion
- ReDim crr(1 To UBound(arr) + 1, 1 To UBound(arr, 2))
- Set dic = CreateObject("scripting.dictionary")
- mm = 1
- For i = 2 To UBound(arr)
- arr(i, 14) = DateValue(arr(i, 14))
- arr(i, 15) = DateValue(arr(i, 15))
- arr(i, 22) = CDbl(arr(i, 22))
- k = arr(i, 1) & arr(i, 2) & arr(i, 3) & arr(i, 14) & arr(i, 15) & arr(i, 29) _
- & arr(i, 30) & arr(i, 32) & arr(i, 31) & arr(i, 21) & arr(i, 22) & arr(i, 23) & arr(i, 33)
- brr(i, 12) = Round(brr(i, 12) / 1.16, 2)
- brr(i, 13) = Round(brr(i, 13), 2)
- kk = brr(i, 2) & brr(i, 3) & brr(i, 4) & brr(i, 6) & brr(i, 7) & brr(i, 8) _
- & brr(i, 9) & brr(i, 11) & brr(i, 12) & brr(i, 13) & brr(i, 14) & brr(i, 15) & brr(i, 20)
- dic(kk) = ""
- If Not dic.exists(k) Then
- mm = mm + 1
- For n = 1 To UBound(arr, 2)
- crr(mm, n) = arr(i, n)
- Next n
- End If
- Next i
- For n = 1 To UBound(arr, 2)
- crr(1, n) = arr(1, n)
- Next n
- With Sheets("报账与台账核实")
- .Cells.ClearContents
- .Range("a1").Resize(UBound(crr), UBound(crr, 2)) = crr
- End With
- End Sub
复制代码 |