ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   color formatting from vbe (https://www.excelbanter.com/excel-programming/411495-color-formatting-vbe.html)

N+

color formatting from vbe
 
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

Gary''s Student

color formatting from vbe
 
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

--
Gary''s Student - gsnu200788


"N+" wrote:

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



All times are GMT +1. The time now is 10:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com