Conditional Row Colours

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I'm looking for a VBA script to colour all the cells in a row (or even just some in a row) a certain colour dependent on the value in the 'A' column cell.
For instance, if cell A1 is Jan-03 then the whole row should be coloured light yellow (or whatever the RGB equivalent is); if cell A2 is Feb-03 then the whole row should be coloured light green; and so on...
Is this possible?
Thanks for you help.
Rob
 
For up to 3 colors you would use Conditional Formatting,
no VBA code involved.
http://www.mvps.org/dmcritchie/excel/condfmt.htm

For more than 3 colors as I think you have, and specifically
because you asked for VBA see
http://www.mvps.org/dmcritchie/excel/event.htm#case


Rob said:
Hi

I'm looking for a VBA script to colour all the cells in a row (or even just some in a row) a certain colour dependent on the value in the 'A' column cell.
For instance, if cell A1 is Jan-03 then the whole row should be coloured light yellow (or whatever the RGB equivalent is); if cell
A2 is Feb-03 then the whole row should be coloured light green; and so on...
 
Rob,

Select all the rows
Goto menu format>Conditional Formatting
Change Condition 1 to Formula Is
Add a formula of =$A1=DATE(2003,1,1)
Click Format
Select the Patterens tab, choose the colour
OKI
Click Add >>>
Change Condition 2 to Formula Is
etc.
OK

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Rob said:
Hi

I'm looking for a VBA script to colour all the cells in a row (or even
just some in a row) a certain colour dependent on the value in the 'A'
column cell.
For instance, if cell A1 is Jan-03 then the whole row should be coloured
light yellow (or whatever the RGB equivalent is); if cell A2 is Feb-03 then
the whole row should be coloured light green; and so on...
 
Rob,

Sub testit()
Dim i As Long, lngLastRow As Long

With Sheet1
lngLastRow = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lngLastRow
Select Case .Cells(i, 1)
Case CDate("1-Jan-03"): .Rows(i).Interior.ColorIndex = 36
Case CDate("1-Feb-03"): .Rows(i).Interior.ColorIndex = 35
End Select
Next
End With
End Sub

Rob

Rob said:
Hi

I'm looking for a VBA script to colour all the cells in a row (or even
just some in a row) a certain colour dependent on the value in the 'A'
column cell.
For instance, if cell A1 is Jan-03 then the whole row should be coloured
light yellow (or whatever the RGB equivalent is); if cell A2 is Feb-03 then
the whole row should be coloured light green; and so on...
 
Back
Top