Checking if al cells are blank in a fixed range

justme101

New Member
Joined
Nov 18, 2017
Messages
34
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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
1,837
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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
 
Solution

justme101

New Member
Joined
Nov 18, 2017
Messages
34
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.
 

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
1,837
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
You're Welcome & Thanks for feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,167
Messages
5,640,534
Members
417,151
Latest member
ChickenTenderer

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
Top