Using VBA to color selected cells if empty?

diannakha

New Member
Joined
Jul 13, 2011
Messages
3
Hello, I'm fairly new to using macros and I need some assistance. I'm not interested in using conditional formatting for this task, but if all else fails I will have to do so.

What I'd like to see happen is once I run a macro, the multiple cells I have selected (either by a predetermined range or by highlighting said cells) will be colored orange if they are empty. The range will probably be B5 to W10, though I'd like it a lot more if it was the cells I had highlighted. I tried using the following code, but of course it only works for one cell.

Code:
 Sub Highlight_Blanks()
'
' Fill any cells which are blank
'
If ActiveCell.Value = "" Then ActiveCell.Interior.Color = 49407
End Sub

Thanks so much for any help you can give me.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Welcome to the board.

Code:
Sub Highligh_Blanks()
Selection.Interior.ColorIndex = xlNone
Selection.SpecialCells(xlCellTypeBlanks).ColorIndex = 46
End Sub
 
Upvote 0
Thanks for the welcome and the reply, Neil! I tried that and I got this error:
Run-time error '438':
Object doesn't support this property or method

If I click the debug button, it highlights this portion of the code:
Code:
Selection.SpecialCells(xlCellTypeBlanks).ColorIndex = 46

If it makes a difference, I'm using Excel 2003. Sorry!
 
Upvote 0
Try

Rich (BB code):
Selection.SpecialCells(xlCellTypeBlanks).Interior.ColorIndex = 46
 
Upvote 0
It works!! THANK YOU SO MUCH!! You've both helped me out tremendously! There isn't enough exclamation marks in the world to tell you how you've instantly ridded me of my headache. :)
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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