Count blank cells in column

as586

New Member
Joined
Nov 28, 2010
Messages
12
Hi there,

I am trying to count the number of blank cells in a column.

So far I have:

Sub findrange()
Dim lastrow As Long

lastrow = Cells(Rows.Count, "B").End(xlUp).Row

Range("h12") = Application.WorksheetFunction.CountBlank(Range("B2" & lastrow))

However this gives me an incorrect figure. The lastrow reference in the last line is where i think the problem is, but on its own it correctly selects the last cell in column B, so im not sure why the reference is wrong.

Any help would be appreciated.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You have a typo.

Instead of:
Rich (BB code):
Range("h12") = Application.WorksheetFunction.CountBlank(Range("B2" & lastrow))
try:
Rich (BB code):
Range("h12") = Application.WorksheetFunction.CountBlank(Range("B2:B" & lastrow))
 
Upvote 0
Great thanks very much for taking the time to help. Im still new to VBA as im sure is obvious.
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,213,507
Messages
6,114,029
Members
448,543
Latest member
MartinLarkin

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