Formatting Issue

mrsushi

Board Regular
Joined
Nov 18, 2006
Messages
180
Office Version
  1. 2010
The below code formats any row column B to N which has a value greater than 30 (in column O)

VBA Code:
Sub FormatRangeEQUITIES()

Range("$B$5:$O$500").Select
With Range("$B$5:$O$500")
.FormatConditions.DELETE
.FormatConditions.Add Type:=xlExpression, Formula1:="=$O5 >= 30"
.FormatConditions(1).Interior.ColorIndex = 37
End With

End Sub


What I need now is to highlight the row if column O equal to "CHECK". The below code doesn't seem to work. Any ideas? Also, how would the code be tweaked to use the last row method instead of specifying a range?

VBA Code:
Sub FormatCHeck()
Range("$B$5:$O$500").Select
With Range("$B$5:$O$500")
.FormatConditions.Add Type:=xlExpression, Formula1:="=$O5 =""CHECK"""
.FormatConditions(1).Interior.ColorIndex = 37
End With

End Sub
 
Last edited by a moderator:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Your code works for me:

Book1
ABCDEFGHIJKLMNOP
4
5CHECK
6CHECK
7NOT
8NOT
9CHECK
10
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B5:O500Expression=$O5 ="CHECK"textYES
 
Upvote 0
"CHECK" is >= 30 so the will be highlighted by the first procedure, you don't need both unless you want to highlight "CHECK" without highlighting >=30, in which case you need to delete any existing rules first.
 
Upvote 0
And as to your second question, I've tweaked your code to use the last row method. Note that it uses column B as the anchor.
VBA Code:
Sub FormatCheck()
Dim lRow As Long
lRow = Cells(Rows.Count, 2).End(xlUp).Row
With Range("$B$5:$O$" & lRow)
    .FormatConditions.Add Type:=xlExpression, Formula1:="=$O5 =""CHECK"""
    .FormatConditions(1).Interior.ColorIndex = 37
End With
Set lastRow = Nothing
End Sub
 
Upvote 0
Many thanks Jason for the tip to remove the formatting,

Thanks Dan for the lastrow code. Much appreciated.
 
Upvote 0
And as to your second question, I've tweaked your code to use the last row method. Note that it uses column B as the anchor.
VBA Code:
Sub FormatCheck()
Dim lRow As Long
lRow = Cells(Rows.Count, 2).End(xlUp).Row
With Range("$B$5:$O$" & lRow)
    .FormatConditions.Add Type:=xlExpression, Formula1:="=$O5 =""CHECK"""
    .FormatConditions(1).Interior.ColorIndex = 37
End With
Set lastRow = Nothing
End Sub

One last question, how would the above code change if the "Check" was also applied to columns P, R and S?
 
Upvote 0
Well, what would you want the conditional formatting to do?
Would it activate if "CHECK" was in any of those columns? (note that CHECK is case sensitive - writing "Check" for example, wouldn't trigger the conditional formatting)
Also, what is getting highlighted? The relevant row from column B to column O? Or from column B to column S?
 
Upvote 0
One last question Dan, how would the above code change if the "Check" was also applied to columns P, R and S?
Sorry - I should have "replied" to that question directly so you could've seen that I had responded. Scroll up to message #7. I ask a few questions,
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,624
Members
449,240
Latest member
lynnfromHGT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top