VBA : Check if Range Empty or Not Empty

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..

i want to check if range blank or not blank fro m range D2:BU1000
this code not work properly how to fix it
VBA Code:
Sub CheckIfCellIsEmpty()
Dim isMyCellEmpty As Boolean
isMyCellEmpty = IsEmpty(Range("D2:BU1000"))
If isMyCellEmpty = False Then
MsgBox "NOT EMPTY"
Else
MsgBox "EMPTY"
End If
End Sub

thanks in advance

susanto
 

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.
You may check with application.counta(range(….))
 
Upvote 0
hi...
i want to show or add code message box like this:
VBA Code:
Set rngSourceRange = Application.InputBox(prompt:="Select range", Title:="Range", Default:="", Type:=8)
VBA Code:

how to combine it?
 
Upvote 0
One way (range with space or "" is considered as NOT empty)
VBA Code:
Sub CheckIfCellIsEmpty()
    If Application.InputBox(prompt:="Select range", Title:="Range", Default:="", Type:=8).Find("*") Is Nothing Then
        MsgBox "EMPTY"
    Else
        MsgBox "NOT EMPTY"
    End If
End Sub

If range with space or "" is considered as empty
VBA Code:
Sub CheckIfCellIsEmpty()
    For Each cell In Application.InputBox(prompt:="Select range", Title:="Range", Default:="", Type:=8)
        If Len(cell) > 0 Then
            MsgBox "NOT EMPTY"
            Exit Sub
        End If
    Next
    MsgBox "EMPTY"
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,851
Messages
6,121,931
Members
449,056
Latest member
denissimo

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