Check for Blank Cells and Continue VBA If Not Blank

Randall

New Member
Joined
Jun 27, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
First time poster! I'm working on a VBA Macro that will give me a quantity at any given time based off a transaction ledger. Each transaction is tied to a warehouse denoted by a 2 character alpha numeric value.

Unfortunately, sometimes the Warehouse isn't present in the column, so I want VBA to recognize all blank cells in column D down to the last populated row (off column A) and rename them "Error". I've managed to do this, but if the data I pull in does not contain any blank cells within that range, then it errors out on me and does not continue the macro. My code is below. I'm sure I've made this way more complicated than it needs to be.

LastRowColumnA = Cells(Rows.Count, 1).End(xlUp).Row
Dim r As Range
Set r = Range("D2:D" & LastRowColumnA).Cells.SpecialCells(xlCellTypeBlanks)
r.Formula = "Error"
Range("A1").Select
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi

So if i understood you correctly

Sub replace_me()
Range("D2:D" & Range("A" & Rows.Count).End(xlUp).Row).Replace What:="", Replacement:="ERROR", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub

Dave
 
Upvote 0
Solution
Hi

So if i understood you correctly

Sub replace_me()
Range("D2:D" & Range("A" & Rows.Count).End(xlUp).Row).Replace What:="", Replacement:="ERROR", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub

Dave
That worked perfectly. Thank you!
 
Upvote 0
Great, thanks for the feedback.

Welcome BTW
 
Upvote 0

Forum statistics

Threads
1,215,525
Messages
6,125,325
Members
449,218
Latest member
Excel Master

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