View Full Version : Fill colour, font colour


nickolm
06-09-2009, 02:37 AM
Hello,

Still quite new to excel vba. I am trying to get something that will look down column A starting at A10 and look at each cell contents. If the value is say 5 then colour font yellow, 4 colour it green etc. Then interrogate next cell and repeat. When it gets to cell A30 it stops. It them does the same thing but using fill colour using column B.

Can somebody please help with the loop, if and select case and so on... been a long time since i did this

Thanks
Matthew

HaHoBe
06-09-2009, 06:31 AM
Hi, Mathew,

why not use the values for the ColorIndex? This oine is for Columns A to C but just the font, for the fill colour please use Interior instead of Font

Sub ColorMe()
Dim lngCounter As Long
Dim lngCol As Long

For lngCol = 1 To 3
For lngCounter = 10 To 30
With Cells(lngCounter, lngCol)
Select Case .Value
Case 5
.Font.ColorIndex = 6
Case 4
.Font.ColorIndex = 4
Case 3
.Font.ColorIndex = 5
Case Else
End Select
End With
Next lngCounter
Next lngCol
End Sub
Ciao,
Holger

nickolm
06-09-2009, 06:54 AM
Thanks

It works!

Cheers for taking the time with something so trivial but, for my purposes, so helpful.

Matthew