2016-07-08 29 views
-1

交替亮點我有一個數據集,如:當數值改變

group  issues 
1   bad 
1   bad 
2   good 
3   bad 
3   bad 
3   bad 
3   bad 
4   bad 
4   bad 
5   bad 
5   bad 
6   good 

我想強調的壞組,整個組的一個顏色。但是,如果連續有兩個壞組,我希望它們交替顯示顏色,並且如果它是一個好的組,則不會顯示顏色。例如:

group  issues 
1   bad (blue) 
1   bad (blue) 
2   good (white) 
3   bad (blue) 
3   bad (blue) 
3   bad (blue) 
3   bad (blue) 
4   bad (green) 
4   bad (green) 
5   bad (blue) 
5   bad (blue) 
6   good (white) 

例如,顏色並不重要。無論如何要爲相當大的數據集自動執行此操作?

+1

你試過[條件格式(https://support.office.com/en-us/article/Use-a-formula-to-apply-conditional-formatting-fed60dfa-1d3f-4e13-9ecb-f1951ff89d7f )? – BruceWayne

回答

0

您可以使用宏是這樣的:

Sub highlights() 
Dim row 
Dim AltColor As Integer 
AltColor = 5 
For row = 2 To 56 
If Cells(row, 2).Value = "bad" Then 
If Cells(row - 1, 1).Value <> Cells(row, 1).Value And Cells(row - 1, Value = "bad" Then 
If AltColor = 5 Then 
    AltColor = 10 
Cells(row, 3).Interior.ColorIndex = AltColor 
Else: 
    AltColor = 5 
    Cells(row, 3).Interior.ColorIndex = AltColor 
End If 
Else 
    Cells(row, 3).Interior.ColorIndex = AltColor 
End If 
End If 
Next row 
End Sub 

我想你的數據從第二row.numbers 5和10 refor以藍色和綠色的顏色開始。