Checking if al cells are blank in a fixed range

justme101

Board Regular
Joined
Nov 18, 2017
Messages
67
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am working on a file, which has some drop down lists and formulas in a range A1:D5. User has to fill up these ranges by using these drop down lists in some cells and the formulated cells will get some values automatically, and then saves the data form this range to a new sheet (that part of the code is done).

I want to check if ALL cells in the range A1:D5 are blank, meaning the user has not filled up anything, and show a msgbox saying "all cells are blank" and exits sub. I am not able to figure this out. I found this code on the net, but it doesn't work:


Dim count As Long
count = WorksheetFunction.CountA(Range("A1:D5"))

If count = 0 Then
MsgBox "All cells are empty, please fill data to be saved."
Else
End If
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
CountA only counts texts Not Numbers. If you have numbers you can use CountBlank or CountIF function. Example:

VBA Code:
Dim count As Long
count = WorksheetFunction.CountBlank(Range("A1:D5"))

If count = 20 Then
MsgBox "All cells are empty, please fill data to be saved."
Else
End If
 
Upvote 0
Solution
CountA only counts texts Not Numbers. If you have numbers you can use CountBlank or CountIF function. Example:

VBA Code:
Dim count As Long
count = WorksheetFunction.CountBlank(Range("A1:D5"))

If count = 20 Then
MsgBox "All cells are empty, please fill data to be saved."
Else
End If
Did the trick! thank you.

But, now there is another issue, I'll open a separate thread for it.
 
Upvote 0
You're Welcome & Thanks for feedback.
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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