Hi Guys
I need to use conditional formatting with VBA to change the colour of certain cells.
I found the code below on this site, but need to format it so it changes the color of the cell rather than the number format.
So if the word "Low" appeared in a cell, I'd want it to be red, for example - please see the draft (incomplete) code that I've written (also below). Can you use the "add color scale" method in this instance? If so, what should be typed afterwards? I've tried "vb" then the color, but that didn't work.
A complete Sub would be greatly appreciated! Thanks in advance.
Sub Macro1()
LastRw = Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To LastRw
If Range("F" & i).Value = 1 Then
Range("F" & i).NumberFormat = """UP"""
Else
Range("F" & i).NumberFormat = "General"
End If
Next
End Sub
I need to use conditional formatting with VBA to change the colour of certain cells.
I found the code below on this site, but need to format it so it changes the color of the cell rather than the number format.
So if the word "Low" appeared in a cell, I'd want it to be red, for example - please see the draft (incomplete) code that I've written (also below). Can you use the "add color scale" method in this instance? If so, what should be typed afterwards? I've tried "vb" then the color, but that didn't work.
A complete Sub would be greatly appreciated! Thanks in advance.
Sub Macro1()
LastRw = Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To LastRw
If Range("F" & i).Value = 1 Then
Range("F" & i).NumberFormat = """UP"""
Else
Range("F" & i).NumberFormat = "General"
End If
Next
End Sub
Code:
Sub CndFrm()
LastRw = Range("P" & Rows.Count).End(xlUp).Row
For i = 1 To LastRw
If Range("P" & i).Value = "Low" Then
Range("P" & i).FormatConditions.AddColorScale
Else
Range("F" & i).NumberFormat = "General"
End If
Next
End Sub