Count Non Blank Cells

S.H.A.D.O.

Well-known Member
Joined
Sep 6, 2005
Messages
1,915
Good evening,

I have a program that uses the line of code ...

Code:
For Each TotalToCheck In Range(Cells(8, 14), Cells(Rows.Count, 14).End(xlUp))

... which works great.
However, when I highlight and delete "x" number of cells and re-run the program it does not recognise the fact that there are less cells with numbers in and gives me the wrong answer.
I have tried to adapt this particular line using DCOUNT & COUNTA etc but without any success.
Has anyone got any ideas please?
Thanks in advance.
 
Hi Joe4,

I think I know why it is counting blank cells within the data as opposed to only cells with data in.
I am using ...

Cells(Rows.Count, 5).End(xlUp))

so it counts from E8:J last cell used and ignores if there is data or not from E8:J last cell.
Kind regards.
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I think I know why it is counting blank cells within the data as opposed to only cells with data in.
I am using ...

Cells(Rows.Count, 5).End(xlUp))

so it counts from E8:J last cell used and ignores if there is data or not from E8:J last cell.
That code, in and of itself, is not counting anything. It is simply finding the last cell in column 5 that has data in it. Take a look at the code I posted in post #4 to count the number of cells in this range that have data in them:
http://www.mrexcel.com/forum/showpost.php?p=2862395&postcount=4
 
Upvote 0
Thanks Joe4,

When I incorporate your code it does indeed tell me the correct number of cells with data in and when I blank some of the cells in the range and run it again, it gives me the correct reduced count.
Regards.
 
Upvote 0
Great! Glad to hear it worked out for you.
 
Upvote 0
Hi Joe4,

Alyhough this part of it works it now proves that the error is somewhere in the bones of the code itself that it is using the blank cells as a combination and adding them to the totals which is wrong.
Thanks in advance..
 
Upvote 0
I am afraid that arays are not my strong point.

However, which version of Excel are you using? If using 2007 or higher, you may want to use COUNTIFS instead of COUNTIF, where you can have more than one condition (and you can check for blank options).

If you are using an older version of Excel, you may want to look at using SUMPRODUCT instead, in which you can have multiple criteria and do summing or counting.
 
Upvote 0
Thanks Joe4,

I am using Excel 2007.
I have tried to put in the extra criteria to only count if the cell or combination is greater than blank but without any success.
The SUMPRODUCT still returns a count on the blank data.
Thanks in advance.
 
Upvote 0
Can you post the COUNTIFS function you tried?
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,287
Members
452,902
Latest member
Knuddeluff

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