blank cells if loop

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
171
Hi guys, im trying to fill all the blank cells in a selected range with the text "no data". however, im doing a monthly report, and its not necessary for each month to have blank cells. so how can I make an if loop where it checks if blank cells exist in the range, if they do, fill with "no data" otherwise, dont do anything. i have this for filling in blank cells


ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).Value = "Null"
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try instead

Code:
ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).Value = "no data"

Looping is not needed as this one-liner does it all at the same time.
 
Last edited:
Upvote 0
So i was looking for an if statement because if there's no blank cells, it gives an error. these are sheets i produce monthly, so sometimes there are no blank cells. basically

if blank cells in range
then fill with "No Data"
else do nothing
 
Upvote 0
Try this mod on Jim's code
Code:
On Error Resume Next
ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).Value = "no data"
On Error Goto 0
 
Upvote 0

Forum statistics

Threads
1,214,996
Messages
6,122,636
Members
449,092
Latest member
bsb1122

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