cristian91493
New Member
- Joined
- Feb 19, 2020
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
I'm trying to change the color of a merged cell (C2) from red to green based on the value of an other cell (E2) and I don't get an error but it also doesn't work. The cells need to be variable rows because I'm making a template for data entry. If cell E2 has a 0 in it then C2 should turn red and if E2 has a 1 in it then C2 should turn green
I've tried isolating all the variables in in my problem and line by line commenting them out to isolate the actual problem. I also specified the sheet that the columns and ranges were on but it didn't seem to do anything although it didn't throw an error. I did get something to work on a test worksheet but it wasn't with the variable rows.
The code i have isolated is
Any help is greatly appreciated. I'm going crazy trying to figure this out.
I've tried isolating all the variables in in my problem and line by line commenting them out to isolate the actual problem. I also specified the sheet that the columns and ranges were on but it didn't seem to do anything although it didn't throw an error. I did get something to work on a test worksheet but it wasn't with the variable rows.
The code i have isolated is
VBA Code:
Sub setCondFormat()
topRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'chooses the first row of the next template input
bottomRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(10, 0).Row
'chooses the last row of the next template input
stageOneEnd = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(2, 0).Row
'sets end parameter for the first stage cell
Sheet1.Range("C" & topRow & ":C" & stageOneEnd).Merge
Sheet1.Range("C" & topRow & ":C" & stageOneEnd).VerticalAlignment = xlCenter
Sheet1.Range("C" & topRow & ":C" & stageOneEnd).HorizontalAlignment = xlCenter
'Start merginging and center column C
Sheet1.Range("E" & topRow & ":E" & bottomRow).Merge
Sheet1.Range("E" & topRow & ":E" & bottomRow).VerticalAlignment = xlCenter
Sheet1.Range("E" & topRow & ":E" & bottomRow).HorizontalAlignment = xlCenter
'End merging and center column E
Sheet1.Range("C" & topRow & "").Interior.ColorIndex = 3
'sets up default color for the C column which is red (stage)
Sheet1.Range("C" & topRow & ":C" & stageOneEnd).Value = "Picture Taken"
'inputs label into the first stage (Picture Taken)
Sheet1.Range("E" & topRow & "").Value = 0
' inputs a zero value into column E to ensure first stage of column C starts off as red
Sheet1.Range("E2").Select
'selects cell E2, I think this is not important at all but is used as a gateway to conditional formatting
With Sheet1.Range("C" & topRow & ":C" & bottomRow & "")
'this selects the range that will change due to the conditional formatting
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"IF(Sheet1.(E" & topRow & ")=0,FALSE,TRUE)"
'the condition for which the stage will change
' if the top cell in column E is equal to 0 then the formatting will not go through but if it isnt equal to zero then it will
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
With .Interior
.PatternColorIndex = xlAutomatic
.Color = 5287936
.TintAndShade = 0
' the new formatting of cell in the C column
End With
End With
End With
End Sub
Any help is greatly appreciated. I'm going crazy trying to figure this out.
Last edited by a moderator: