ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Highlighting a range using a Macro based on more then 5 conditions (https://www.excelbanter.com/excel-programming/377186-highlighting-range-using-macro-based-more-then-5-conditions.html)

ALEX

Highlighting a range using a Macro based on more then 5 conditions
 
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


Bob Phillips

Highlighting a range using a Macro based on more then 5 conditions
 
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)

"Alex" wrote in message
...
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





All times are GMT +1. The time now is 03:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com