Application.WorkSheetFunction.CountA

kc_native

Board Regular
Joined
Jan 20, 2009
Messages
176
I am using the following code to count the non-blank cells in various ranges, based on previously defined variables, and the first line of code is returning the correct count, but the next two are returning zero, when there are 14 non-blank cells in each defined range. In pointing to the variables, they are all set to the right values, so I am at a loss as to why they are returning zeros. What am I doing wrong??

Code:
Cells(lngRow, Over_30_Col) = Application.WorksheetFunction.CountA(Cells(3, Over_30_Col), Cells(lngRow - 1, Over_30_Col))
        Cells(lngRow, NCR_Col) = Application.WorksheetFunction.CountA(Cells(3, NCR_Col), Cells(lngRow - 1, NCR_Col))
        Cells(lngRow, Disp_Col) = Application.WorksheetFunction.CountA(Cells(3, Disp_Col), Cells(lngRow - 1, Disp_Col))
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi

Each Application.WorksheetFunction.CountA() is performing a count in only 2 cells. Maybe you want to count in the range between the 2 cells? In that case use Range(c1,c2).
 
Upvote 0
Hi

Each Application.WorksheetFunction.CountA() is performing a count in only 2 cells. Maybe you want to count in the range between the 2 cells? In that case use Range(c1,c2).
Of course. That makes sense. Chalk it up to newbie brain lock!

Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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