Range ActiveCell - vba write values to none-active cells as well

kit99

Active Member
Joined
Mar 17, 2015
Messages
352
Got a ws, were I want to fill inn value "n/a" in blank cells.
The ws only holds columns from A to M, but when I run the code below it fills in "n/a" in row 1, cells N and as far to the right as it is allowed before I stop the vba manually...

What is wrong With this code?
And if there is something to the formatting of row 1 (headers), how can I change the code so that it starts from row 2?

And if anyone can fill in how to use range columns A:M + Down to last row, I can even try this out...

Code:
    For Each cell In Range(ActiveCell, ActiveCell.End(xlDown).End(xlToRight))
        If IsEmpty(cell) Then
        cell.Value = "n/a"
        cell.HorizontalAlignment = xlRight
        End If
    Next
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this:
Code:
Sub Fill_Me()
For Each c In ActiveSheet.UsedRange
If c.Value = "" Then c.Value = "n/a"
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,521
Messages
6,055,891
Members
444,831
Latest member
iceonmn

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