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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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