修正对比表AB列重复值问题。- Sub ykcbf() '//2024.7.9
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("对比表")
- With sh
- xs = .[c2].Value
- yf = Split(.[f2].Value, "-")
- End With
- With Sheets("2024年")
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r, c)
- End With
- ReDim brr(1 To UBound(arr), 1 To 2)
- b = Array(15, 9, 10, 14, 24, 11)
- For i = 2 To UBound(arr)
- If arr(i, 38) = xs And arr(i, 41) = "是" Then
- If Val(arr(i, 33)) >= Val(yf(0)) And Val(arr(i, 33)) <= Val(yf(1)) Then
- s = arr(i, 4) & "|" & arr(i, 28)
- If Not d1.exists(s) Then
- m = m + 1
- d1(s) = m
- brr(m, 1) = arr(i, 4)
- brr(m, 2) = arr(i, 28)
- End If
- If Not d.exists(s) Then
- d(s) = Array(arr(i, 15), arr(i, 9), arr(i, 10), arr(i, 14), arr(i, 24), arr(i, 11))
- Else
- t = d(s)
- For x = 0 To 5
- t(x) = t(x) + arr(i, b(x))
- Next
- d(s) = t
- End If
- End If
- End If
- Next
- On Error Resume Next
- With sh
- .UsedRange.Offset(3).ClearContents
- .[a4].Resize(m, 2) = brr
- With .[a4].Resize(m, 16)
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For i = 4 To m + 3
- s = .Cells(i, 1) & "|" & .Cells(i, 2)
- If d.exists(s) Then
- t = d(s)
- .Cells(i, 3) = t(0)
- .Cells(i, 4) = t(1)
- .Cells(i, 5) = t(2)
- .Cells(i, 6) = t(3)
- .Cells(i, 7) = t(3) / t(2)
- .Cells(i, 8) = t(4) / t(2)
- .Cells(i, 9) = t(5) / t(2)
- End If
- Next
- End With
- d.RemoveAll
- With Sheets("2023年")
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r, c)
- End With
-
- For i = 2 To UBound(arr)
- If arr(i, 38) = xs And arr(i, 41) = "是" Then
- If Val(arr(i, 33)) >= Val(yf(0)) And Val(arr(i, 33)) <= Val(yf(1)) Then
- s = arr(i, 4) & "|" & arr(i, 28)
- If Not d.exists(s) Then
- d(s) = Array(arr(i, 15), arr(i, 9), arr(i, 10), arr(i, 14), arr(i, 24), arr(i, 11))
- Else
- t = d(s)
- For x = 0 To 5
- t(x) = t(x) + arr(i, b(x))
- Next
- d(s) = t
- End If
- End If
- End If
- Next
- With sh
- For i = 4 To m + 3
- s = .Cells(i, 1) & "|" & .Cells(i, 2)
- If d.exists(s) Then
- t = d(s)
- .Cells(i, 10) = t(0)
- .Cells(i, 11) = t(1)
- .Cells(i, 12) = t(2)
- .Cells(i, 13) = t(3)
- .Cells(i, 14) = t(3) / t(2)
- .Cells(i, 15) = t(4) / t(2)
- .Cells(i, 16) = t(5) / t(2)
- End If
- Next
- End With
- Set d = Nothing
- MsgBox "OK!"
- End Sub
复制代码
|