Fill color in Blank cells

gbabu

New Member
Joined
Aug 5, 2011
Messages
12
Hi,

I have a doubt in Excel. In A Column, i have filled few different color and few blank cells. In the Blank cells, i have to fill only Green color.

Please advice me, how to write VBA Macro

Thanks in advance
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Assuming that those cells are not blank try

Code:
Sub FillGreen()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("A" & i)
        If .Interior.ColorIndex = xlNone Then .Interior.ColorIndex = 4
    End With
Next i
End Sub
 
Upvote 0
If you want to select only the blank cells in a worksheet range you can do it via the GO TO dialog using CTRL+G and selecting Blanks. If you run the macro recorder while doing this you will get something like:


Code:
Selection.SpecialCells(xlCellTypeBlanks).Select

You can modify this code as needed, for example:


Code:
Activesheet.UsedRange.SpecialCells(xlCellTypeBlanks).Interior.Color = RGB(255,0,0)
 
Upvote 0
Assuming that those cells are not blank try

Code:
Sub FillGreen()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("A" & i)
        If .Interior.ColorIndex = xlNone Then .Interior.ColorIndex = 4
    End With
Next i
End Sub
Thank you so much. code is working fine Peter
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top