writing coloured text with formulas

N

NDBC

I am using the code below to save the time (time5.text) in a cell. It is all
working fine. What I want to do is put an if statement in that when certain
criteria are met the same value etc gets written but in blue coloured text in
the spreadsheet.


Range("G" & riderCell.Row).End(xlToRight).Offset(0, 1) = Time5.Text

Something along the lines of

If blah blah is true Then
Range("G" & riderCell.Row).End(xlToRight).Offset(0, 1) = Time5.Text
Range("G" & riderCell.Row).End(xlToRight).Offset(0, 1).forecolor = vbblue
Endif

Thanks
 
S

Shane Devenshire

Hi,

the line would be

Range("G" & riderCell.Row).End(xlToRight).Offset(0, 1).Font.ColorIndex = 5

You can use the Font.Color or the Font.ColorIndex method, you get more
colors to "easily" choose from if you use the ColorIndex. The best idea is
to turn on the recorder and change to font color of a cell and then turn the
macro recorder off and see what the color index was that got recorded. 5
above gives a blue.

When using vbBlue type arguments you have only 8 colors to choose from
When using the ColorIndex method there are 56
but if you want more than you can use

Range("A1").Font.Color = RGB(255, 0, 0)

Which gives you access to 16 million but of course you need to know the
appropriate values.
 

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