Highlighting a range using a Macro based on more then 5 conditions

G

Guest

Hi, I'm pretty new with VBA. I'm trying to highlight a range of cells for
example (A10:N500) based on cells located in column P. If P10=CA Then
A10:N10 will be highlighted yellow Else If P11=GI Then A11:N11 will be
highlighted orange and about three more coniditons. I would appreciate a
code for this.

-Thank you
 
B

Bob Phillips

Based upon your previous post I guess that you want something like this

Sub Test()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "P").End(xlUp).Row
For i = 1 To iLastRow
With Cells(i, "P")
Select Case .Value
Case "GI": Cells(i, "A").Resize(, 12) _
.Interior.ColorIndex = 46 'orange
Case "CA": Cells(i, "A").Resize(, 12) _
.Interior.ColorIndex = 6 'yellow
'etc.
End Select
End With
Next i

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