Vba for determing UsedRange when blank (used earlier) cells is present

kit99

Active Member
Joined
Mar 17, 2015
Messages
352
I've been using this one:
Code:
    For Each c In ActiveSheet.UsedRange
    If c.Value = "" Then c.Value = "n/a"
    Next
... for adding "n/a" to blank cells in UsedRange.

But now I'm getting into trouble 'cause of earlier use of this ws/sheet. When running code, the code applies "n/a" to cells in rows below UsedRange. This is rows that had data in them the last time I used this sheet/code.
So I tried to put his line above my code:
Code:
    Worksheet.UsedRangeIncludesFormatting = False
But it ends in error: Run-time error '424': Object required.
Any ideas on how to fix this?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
One option would be
Code:
Dim x
Set x = ActiveSheet.UsedRange
For Each C In ActiveSheet.UsedRange
   If C.Value = "" Then C.Value = "n/a"
Next
or maybe just
Code:
Range("A1").CurrentRegion.SpecialCells(xlBlanks).Value = "n/a"
 
Upvote 0
One option would be
Code:
Dim x
Set x = ActiveSheet.UsedRange
For Each C In ActiveSheet.UsedRange
   If C.Value = "" Then C.Value = "n/a"
Next
or maybe just
Code:
Range("A1").CurrentRegion.SpecialCells(xlBlanks).Value = "n/a"


Your first suggestion doesn't do any good. It still adds "n/a" to cells in previous used rows below my new range.
But your second suggestion works great.

Thanks a lot for helping out! :)
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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