這應該做的伎倆:
Sub test_CairoCoder()
Dim wS As Worksheet, _
LastRow As Long, _
ColorChg As Boolean, _
OrderNb As String
Set wS = ActiveSheet
ColorChg = False
With wS
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
OrderNb = wS.Cells(2, 1)
For i = 2 To LastRow
If .Cells(i, 1) <> .Cells(i + 1, 1) And .Cells(i, 1) <> .Cells(i - 1, 1) Then
ColorChg = Not ColorChg
If ColorChg Then
.Range(.Cells(i, "A"), .Cells(i + 1, "A")).Interior.Color = vbRed
Else
.Range(.Cells(i, "A"), .Cells(i + 1, "A")).Interior.Color = vbYellow
End If
Else
If .Cells(i, 1) <> .Cells(i + 1, 1) Then
Else
If OrderNb <> .Cells(i, 1) Then
OrderNb = .Cells(i, 1)
ColorChg = Not ColorChg
Else
End If
If ColorChg Then
.Range(.Cells(i, "A"), .Cells(i + 1, "A")).Interior.Color = vbRed
Else
.Range(.Cells(i, "A"), .Cells(i + 1, "A")).Interior.Color = vbYellow
End If
End If
End If
Next i
End With
MsgBox "All done!", vbInformation + vbOKOnly
End Sub
如果只有數字,會不會有條件格式化?說偶數紅色和奇數黃色? –
它不一定是奇數,甚至可能是整張紙是偶數或整張紙都是奇數,但具有不同的重複值。 – CairoCoder