Excel用条件格式或VBA,把连续相同的用颜色区分开,单一的则不用标注颜色,怎样可以做到,如图片样式,谢谢!

如题所述

第1个回答  推荐于2016-03-31
'以下代码应该可以满足你的需求
Sub x()
Dim r&, color%
color = 6
For r = 1 To [i65536].End(xlUp).Row()
If r = 1 Then
If Cells(r, 9) = Cells(r + 1, 9) Then
Cells(r, 4).Interior.ColorIndex = color
End If
Else
If Cells(r, 9) = Cells(r - 1, 9) Then
Cells(r, 4).Interior.ColorIndex = color
Else
If Cells(r, 9) = Cells(r + 1, 9) Then
If color = 6 Then color = 8 Else color = 6
Cells(r, 4).Interior.ColorIndex = color
End If
End If
End If
Next
End Sub本回答被提问者采纳
相似回答