Condional Formatting with MACRO

A

Anift

Hello all
I would like to hightlight a row based on a value in a cell. I know it is
possible. I just don't know how to go about doing. i'd like to use vba if
possible.
In Column B1 and down, I have open, close, etc. If Open is selected, I would
like that row to be highlighted. Could someone help me out???

Thanks
 
B

Bob Phillips

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "B:B"

If Not Intersect(Target, rang(WS_RANGE)) Is Nothing Then
If Target.Value = "Open" Then
Target.EntireRow.Interior.ColorIndex = 38
Else
Target.EntireRow.Interior.ColorIndex = xlColorIndexNone
End If
End If

End Sub


This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
A

Anift

Hello Bob,
Thanks for the response, i really appreciate..
But there is something wrong in this code

I am getting error on line " If Not Intersect(Target, rang(WS_RANGE)) Is
Nothing Then"
Its highlighing the word "rang",
Can we do anything about it?

any help will be appreciated.

Thanks
 
B

Bob Phillips

Sorry, missed an e

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "B:B"

If Not Intersect(Target, Range(WS_RANGE)) Is Nothing Then
If Target.Cells.Count = 1 Then
If Target.Value = "Open" Then
Target.EntireRow.Interior.ColorIndex = 38
Else
Target.EntireRow.Interior.ColorIndex = xlColorIndexNone
End If
End If
End If

End Sub




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top