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.
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,560
Office Version
  1. 365
Platform
  1. Windows
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))
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
12,420
Office Version
  1. 365
Platform
  1. Windows
The last part should be "B2:B" & lastrow
 

as586

New Member
Joined
Nov 28, 2010
Messages
12
Great thanks very much for taking the time to help. Im still new to VBA as im sure is obvious.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,560
Office Version
  1. 365
Platform
  1. Windows
You are welcome.
Glad we were able to help!
 

Watch MrExcel Video

Forum statistics

Threads
1,127,256
Messages
5,623,669
Members
415,983
Latest member
MusicMan

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