问题
I am trying to create a macro that will basically highlight like values in column A the same color and alternate between a blue and white coloring. Therefore, exact values are grouped together by color.
Hope this makes sense? At this moment I am doing the highlighting manually (but there are 12000+ rows so thats not a smart idea). I am not so great with VBA yet and am still trying to learn more.
So basically this macro will check is the value in cell x of column A is the same of cell x+1 in the same column; if it is then they will be highlighted white. Now if cell x+2 is not the same value as x but cell x+2 and x+3 are the same values, they will be highlighted in the blue color. I need teh color to spread through the WHOLE ROW
Here is a visual(imagine the whole row as colored):

回答1:
This will highlight the second cell in the column. The color might now be the extact color you want though.
EDIT2: added the definition for testcell1, first,Second and Added Report as worksheet code
edit 3: changed <> to =
Sub runthis()
'Dim row As Integer
Dim TestCell As String
Dim first As String
Dim Second As String
Dim TestCell1 As String
Dim lastcell As Integer
Sheets("sheet1").Select
Dim Report As Worksheet
Set Report = Excel.Worksheets("Sheet1")
lastcell = Sheets("sheet1").Cells(Rows.Count, "A").End(xlUp).row
For row = 1 To lastcell
TestCell = "A" & CInt(row)
TestCell1 = "A" & (CInt(row) + 1)
first = Range(TestCell).Value
Second = Range(TestCell1).Value
If first = Second Then
Report.Cells(row, 1).Interior.ColorIndex = 3
End If
Next row
End Sub
来源:https://stackoverflow.com/questions/16963219/scripting-in-excel-highlighting-like-values