Daniel0sb
02-24-2018, 08:35 PM
Hey my friends,
I am a beginner at VBA.. I have a data set and i would like to color the Rows based on the color labeled in the "C" column and if the value in the given cell is "1"....For all other data i have labeled it test.
Data Set:
21694
Currently i am able to color the rows based on the color under column "C" but i can't get VBA to recognize the "And r2.Value = 1" portion of my code.
Sub ColorRows()
Dim i As Long, r1 As Range, r2 As Range
For i = 3 To 7
Set r1 = Range("C" & i)
Set r2 = Range("E" & i & ":K" & i)
If r1.Value = "Blue" And r2.Value = 1 Then r2.Interior.ColorIndex = 5
If r1.Value = "Blue" Then r2.Font.ColorIndex = 5
If r1.Value = "Red" Then r2.Interior.ColorIndex = 3
If r1.Value = "Red" Then r2.Font.ColorIndex = 3
If r1.Value = "Orange" Then r2.Interior.ColorIndex = 46
If r1.Value = "Orange" Then r2.Font.ColorIndex = 46
If r1.Value = "Gray" Then r2.Interior.ColorIndex = 48
If r1.Value = "Gray" Then r2.Font.ColorIndex = 48
If r1.Value = "Turquoise" Then r2.Interior.ColorIndex = 8
If r1.Value = "Turquoise" Then r2.Font.ColorIndex = 8
Next i
End Sub
I would like the Cells with a value of 1 to remain colored but the other cells to remain uncolored.
21695
I am a beginner at VBA.. I have a data set and i would like to color the Rows based on the color labeled in the "C" column and if the value in the given cell is "1"....For all other data i have labeled it test.
Data Set:
21694
Currently i am able to color the rows based on the color under column "C" but i can't get VBA to recognize the "And r2.Value = 1" portion of my code.
Sub ColorRows()
Dim i As Long, r1 As Range, r2 As Range
For i = 3 To 7
Set r1 = Range("C" & i)
Set r2 = Range("E" & i & ":K" & i)
If r1.Value = "Blue" And r2.Value = 1 Then r2.Interior.ColorIndex = 5
If r1.Value = "Blue" Then r2.Font.ColorIndex = 5
If r1.Value = "Red" Then r2.Interior.ColorIndex = 3
If r1.Value = "Red" Then r2.Font.ColorIndex = 3
If r1.Value = "Orange" Then r2.Interior.ColorIndex = 46
If r1.Value = "Orange" Then r2.Font.ColorIndex = 46
If r1.Value = "Gray" Then r2.Interior.ColorIndex = 48
If r1.Value = "Gray" Then r2.Font.ColorIndex = 48
If r1.Value = "Turquoise" Then r2.Interior.ColorIndex = 8
If r1.Value = "Turquoise" Then r2.Font.ColorIndex = 8
Next i
End Sub
I would like the Cells with a value of 1 to remain colored but the other cells to remain uncolored.
21695