VBA Counting blank cells in multiple ranges

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
778
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have written this code to find blank cells in a range. It works fine with one or two ranges but not for three or more. Any more than two gives a Complie error.

Any Ideas?

Sub CountBlank()
MsgBox WorksheetFunction.CountBlank(Range("TheRange1", "TheRange2", "TheRange3"))
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Thanks for the reply. But I'm getting a run time error. Using that line.
 
Upvote 0
Hmm, should have tested that shouldn't I? It seems COUNTBLANK works differently from the SUM and COUNT versions of the worksheetfunction in that it won't accept multiple ranges.

Incidentally, when you use the form you were with two ranges ie Range("TheRange1","TheRange2") then they define a single rectangular range from the first cell of TheRange1 to the last cell of TheRange2.
 
Upvote 0
I have ended up using the code below, due to the limit of two ranges per line. I really don't know why there is a two limit. I only have eight ranges to add so it's not to big.

Thanks for taking the time to help. Strange that two limit?

Sub test()

Dim TheRange01 As Long
Dim TheRange02 As Long

TheRange01 = WorksheetFunction.CountBlank(Range("TheRange1", "TheRange2"))
TheRange02 = WorksheetFunction.CountBlank(Range("TheRange3", "TheRange4"))

MsgBox (TheRange01 + TheRange02)

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

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