robertwp7472
New member
Hello All Gurus,
I have been working on a sub that will change the row color when the value in Column C changes. I need it to alternate between two different colors every time the value changes starting with Row 3. Column C has repeating values and then it'll change, repeat again, etc. Like this:
8081837591 Yellow
8098922005 White
8098922005 White
8098922005 White
8098866848 Yellow
8098866848 Yellow
8099154851 White
8098281091 Yellow
8098281093 White
8098941580 Yellow
8099018602 White
8099018602 White
8098082163 Yellow
8098385731 White
8098385732 Yellow
8098385732 Yellow
8098385732 Yellow
8098385732 Yellow
8098686076 White
I am trying to use a piece of code I found on Stack Overflow's website which according to the instructions should work but I keep getting errors. Here is what I have:
The error says "Variable Not Defined" So I tried adding "Dim RwColor as Variant" and then it got stuck on the next line saying "Object not defined". I tried a few different thing but each time the it kept throwing different errors; now I'm just frustrated.
What am I missing in the Syntax? Any help is greatly appreciated.
I have been working on a sub that will change the row color when the value in Column C changes. I need it to alternate between two different colors every time the value changes starting with Row 3. Column C has repeating values and then it'll change, repeat again, etc. Like this:
8081837591 Yellow
8098922005 White
8098922005 White
8098922005 White
8098866848 Yellow
8098866848 Yellow
8099154851 White
8098281091 Yellow
8098281093 White
8098941580 Yellow
8099018602 White
8099018602 White
8098082163 Yellow
8098385731 White
8098385732 Yellow
8098385732 Yellow
8098385732 Yellow
8098385732 Yellow
8098686076 White
I am trying to use a piece of code I found on Stack Overflow's website which according to the instructions should work but I keep getting errors. Here is what I have:
Code:
Private Sub ShadeRows()
Dim Order As Long, NxtOrder As Long, lr As Long, R As Long
Dim Clr As Integer
Application.ScreenUpdating = False
lr = ActiveSheet.Range("C3" & Rows.Count).End(xlUp).Row
' Enter desired color codes here
' (19 is Pastel Yellow, 1 is White)
[COLOR=#ff0000] RwColor[/COLOR] = Array(19, 2)
Clr = 0 ' Used to toggle between the two colors
For R = 2 To lr
[COLOR=#ff0000]Order = Cells(R, 1).Value[/COLOR]
NxtOrder = Cells(R - 1, 1).Value
If Order <> Nxtorder Then Clr = 1 - Clr
' Select only the columns that are used
Range("A" & R & ":L" & R).Interior.ColorIndex = RwColor(Clr)
Next R
Application.ScreenUpdating = True
End Sub
The error says "Variable Not Defined" So I tried adding "Dim RwColor as Variant" and then it got stuck on the next line saying "Object not defined". I tried a few different thing but each time the it kept throwing different errors; now I'm just frustrated.
What am I missing in the Syntax? Any help is greatly appreciated.