|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub comp1()
- Dim ar As Variant, br As Variant
- Dim mr As Long, tmpa As Variant, tmpd As Variant
- Dim ardiffa As Variant, ardiffd As Variant
- Dim dica As Object, dicd As Object
- Dim i&, j&, k&
- Dim lngCT&, lngCTa&, lngCTd&
- Dim TTL#, MNTa#, MNTd#
- Dim strtmp As String
- Set dica = CreateObject("Scripting.Dictionary")
- Set dicd = CreateObject("Scripting.Dictionary")
-
- With Worksheets("0、差异数据")
- .Activate
- ReDim tmpa(1 To .Cells(Rows.Count, "A").End(xlUp).Row - 4, 1 To 2)
- ReDim tmpd(1 To .Cells(Rows.Count, "d").End(xlUp).Row - 4, 1 To 2)
- If .Cells(Rows.Count, "A").End(xlUp).Row > .Cells(Rows.Count, "D").End(xlUp).Row Then
- mr = .Cells(Rows.Count, "A").End(xlUp).Row
- Else
- mr = .Cells(Rows.Count, "D").End(xlUp).Row
- End If
- ReDim ar(1 To mr - 4, 1 To 2)
- For i = 5 To mr
- ar(i - 4, 1) = .Cells(i, 1): ar(i - 4, 2) = .Cells(i, 4)
- Next
- End With
- For i = 1 To UBound(ar)
- MNTa = MNTa + ar(i, 1)
- If Len(ar(i, 2)) Then MNTd = MNTd + ar(i, 2)
- If Len(ar(i, 1)) And dica.exists(ar(i, 1)) = False Then
- dica(ar(i, 1)) = i
- End If
- If Len(ar(i, 2)) And dicd.exists(ar(i, 2)) = False Then
- dicd(ar(i, 2)) = i
- End If
- Next
- TTL = MNTa + MNTd
- For i = 2 To UBound(ar)
- If dica.exists(ar(i, 2)) Then
- dica.Remove ar(i, 2)
- End If
- If dicd.exists(ar(i, 1)) Then
- dicd.Remove ar(i, 1)
- End If
- Next
- br = dicd.items
- If dica.Count > 1 Then ReDim ardiffa(1 To dica.Count, 1 To 1)
- If dicd.Count > 1 Then ReDim ardiffd(1 To dicd.Count, 1 To 1)
- For i = 1 To UBound(ar)
- If i = dica(ar(i, 1)) Then
- tmpa(dica(ar(i, 1)), 1) = ar(i, 1): tmpa(dica(ar(i, 1)), 2) = "财政有,前台没有"
- lngCTa = lngCTa + 1
- ardiffa(lngCTa, 1) = ar(dica(ar(i, 1)), 1)
- End If
- If i = dicd(ar(i, 2)) Then
- tmpd(dicd(ar(i, 2)), 1) = ar(i, 2): tmpd(dicd(ar(i, 2)), 2) = "前台有,财政没有"
- lngCTd = lngCTd + 1
- ardiffd(lngCTd, 1) = ar(dicd(ar(i, 2)), 2)
- End If
- Next
- With Worksheets("0、差异数据")
- .Range("a3").ClearContents: .Range("d3").ClearContents: .Range("h1:h3").ClearContents
- .Range("b5:c" & mr).ClearContents: .Range("e5:f" & UBound(tmpd)).ClearContents
- .Range("a3") = MNTa: .Range("h1") = MNTa: .Range("d3") = MNTd: .Range("h2") = MNTd: .Range("h3") = MNTa - MNTd
- .Range("b5:c" & mr) = tmpa: Range("e5:f" & UBound(tmpd)) = tmpd
- End With
- End Sub
复制代码 |
|