I don't know VBA well. Ivesleo answered an old post called, 'Shading entire column based on change of value'. Link to Shade Row Post
I used his code and it works but I don't know how to change the code to modify it for what I need.
- I have columns of weeks (column B) when we will schedule a project in certain cities (column C). Now the codes highlights the rows for every change in column B or (2nd column/week column). I need the code to note every change in the week within that city, so that when we go to another city, say Piley, it will not highlight the W1N4 for Piley b/c it first noticed that we are in a new city. Kind of like a custom sort with 2 levels, the city first, then the week. I don't want it to highlight based on the change in city, just note that there is a change in city and then highlight within that city based on the change in value in week column.
- How do you just shade row to the end of the data in that row? I tried End(xlRight).Select, End(xlLeft).Select, and End(xlUp).Row.Select but they didn't work.
- Is colorIt something he made up? I don't understand what it does and how Excel knows what to do with it? Again, I'm a beginner. Thank you for your help.
Week / City
W1N1 Silverton W1N1 Silverton W2N3 Silverton W1N4 Silverton W1N4 Piley
Sub color()
'Replace the 2 values of G = and C= by the number of the column containing _
'the values being referenced.
Dim g As Long
Dim c As Integer
Dim colorIt As Boolean
g = 2
c = 2
colorIt = True
Do While Cells(g, c) <> ""
test_value = Cells(g, c)
Do While Cells(g, c) = test_value
If colorIt Then
Cells(g, c).EntireRow.Select
Selection.Interior.ColorIndex = 15
Else
Cells(g, c).EntireRow.Select
Selection.Interior.ColorIndex = x1None
End If
g = g + 1
Loop
colorIt = Not (colorIt)
Loop
End Sub
The following code has been tailored for your situation:
Note: The variable
colourIt
(wascolorIt
, but I'm Australian, so I'm going to use the English spelling!!) is simply a Boolean variable, which therefore can take the valueTrue
orFalse
. The code is toggling between the two possible values (using the codecolourIt = Not colourIt
) each time the criteria being tested for changes.Poster's Edit: Thank you so much. I just wanted to add here how I changed it to further fit my situation. I changed it as follows: I changed the color to a light orange using the RGB palette (I guess that is what it's called) and I changed .Range(.Cells(r, "B"),etc. to .Range(.Cells(r, "A"), etc. b/c it was highlighting the row beginning at column B vs. starting at column A.
I'm going to post a further thank you in the Comments.