- Sub aa()
- Dim i&, d As Object, ar, n&, m&, n1&, m1&
- Set d = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- With Sheet1
- .UsedRange.ClearFormats
- ar = .UsedRange
- For i = 2 To UBound(ar)
- If d.exists(ar(i, 1)) Then
- m = Split(d(ar(i, 1)), "/")(1)
- If ar(i, 2) <> Val(Split(Split(d(ar(m, 4)), "/")(0), "-")(1)) Then
- .Cells(i, "f").Font.ColorIndex = 3
- .Cells(m, "g").Font.ColorIndex = 3
- d(ar(i, 1)) = Split(d(ar(i, 1)), "-")(1)
- End If
- .Range("g" & m).Resize(1, 2).Interior.ColorIndex = 0
- Else
- n = n + 1
- d(ar(i, 1)) = n & "-" & ar(i, 2) & "/" & i
- .Range("e" & i).Resize(1, 2).Interior.ColorIndex = 4
- End If
- If d.exists(ar(i, 4)) Then
- m1 = Split(d(ar(i, 4)), "/")(1)
- If ar(i, 3) <> Val(Split(Split(d(ar(m1, 1)), "/")(0), "-")(1)) Then
- .Cells(i, "g").Font.ColorIndex = 3
- .Cells(m1, "f").Font.ColorIndex = 3
- d(ar(i, 4)) = Split(d(ar(i, 4)), "-")(1)
- End If
- .Range("e" & m1).Resize(1, 2).Interior.ColorIndex = 0
- Else
- n1 = n1 + 1
- d(ar(i, 4)) = n1 & "-" & ar(i, 3) & "/" & i
- .Range("g" & i).Resize(1, 2).Interior.ColorIndex = 4
- End If
- n = 0
- n1 = 0
- Next
- .UsedRange.HorizontalAlignment = xlCenter
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |