Macro VBA: Check If Column is empty

harky

Active Member
Joined
Apr 8, 2010
Messages
405
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
I had data from

A to T

I want to check the entire column of D, if there is a empty cell. Marco will aborted.
MsgBox "Pls ensure Col D is not empty"
 
Thanks! I change but still not working

there is no empty cell on D. The marco is not running.

You have changed the 4th line, not the 2nd!
Code:
Dim dRng As Range, lRow As Long
[U]lRow = Cells(Rows.Count, "J").End(xlUp).Row[/U]
On Error Resume Next
    Set dRng = Range("D1:D" & lRow).SpecialCells(xlBlanks)
On Error GoTo 0
If dRng Is Nothing Then
    MsgBox "Pls ensure Col D is not empty", vbExclamation
    Exit Sub
End If
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I missed a 'Not' in the code, change it to
Code:
Dim dRng As Range, lRow As Long
lRow = Cells(Rows.Count, "J").End(xlUp).Row
On Error Resume Next
    Set dRng = Range("D1:D" & lRow).SpecialCells(xlBlanks)
On Error GoTo 0
If Not dRng Is Nothing Then
    MsgBox "Pls ensure Col D is not empty", vbExclamation
    Exit Sub
End If

Did you know that you can reply without repeating the previous post each time?
 
Upvote 0
Thanks! this work great :)

I missed a 'Not' in the code, change it to
Code:
Dim dRng As Range, lRow As Long
lRow = Cells(Rows.Count, "J").End(xlUp).Row
On Error Resume Next
    Set dRng = Range("D1:D" & lRow).SpecialCells(xlBlanks)
On Error GoTo 0
If Not dRng Is Nothing Then
    MsgBox "Pls ensure Col D is not empty", vbExclamation
    Exit Sub
End If

Did you know that you can reply without repeating the previous post each time?
 
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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