color formatting from vbe

  • Thread starter Thread starter N+
  • Start date Start date
N

N+

hi all.. i need to make the macro to format all the cells of my workbook like
this...

if cell is equal to 2 then
paint it red
end if

if cell is equal to 1 then
paint it blue
end if

help me !! byyy
 
You could use Conditional Formatting, but with VBA:

Sub color_them()
For Each r In ActiveSheet.UsedRange
v = r.Value
If v = 1 Then
r.Interior.ColorIndex = 3
Else
If v = 2 Then
r.Interior.ColorIndex = 5
End If
End If
Next
End Sub
 

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

Back
Top