cell color within a function

  • Thread starter Thread starter billQ
  • Start date Start date
B

billQ

Hello,
Is it possible to change a cell interior color within a function or must
that be done throught a sub.
thanks
billq
 
you can do it in code, or use Conditional Formatting -
though this only allows three conditions.

Sub ColorTest()
Dim i As Long
On Error Resume Next
Do
Cells(i + 1, 1) = i
Cells(i + 1, 2).Interior.ColorIndex = i
i = i + 1
Loop While Err.Number = 0

End Sub

Patrick Molloy
Microsoft Excel MVP
 
Bill,

Why not use CF as Patrick suggests.

With A1:A4 selected, go to Format>Conditional Formatting
For Condition1
Choose FormulaIs
Add a formula of =MOD(ROW(),2)=0
Select the format button, pattern tab an d set the colour
OK
For Condition2, repeat with a formula of =MOD(ROW(),2)=1 and a different
colour

This CF can be copied as the range changes
 
Back
Top