Counting cells which are != empty

excel_user_1966

New Member
Joined
Mar 24, 2002
Messages
7
I have:

------------------
Sub CountHowManyRowOfData()
MsgBox ActiveSheet.UsedRange.rows.Count
End Sub
---------------------

to count how many rows have data.

However, I've got formatted cells (with borders, etc) which are being counted in this too.... whilst i only wish to count how many rows from say the range B6 to I2000 are being used WITH DATA IN THEM. I don't want the formatted but technically empty cells in this count. Is there a way to do this?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You could use the CurrentRegion property if the rows you want to count are adjacent:

Activesheet.cells(5,5).CurrentRegion.Rows.Count

should do the trick, supposing that the top left cell of your table is cell E5

Marc
 
Upvote 0
I didn't realise that if a user using my spreadsheet were to use the Autofilter it would still count all the rows; is there anyway to only let it count the stuff that's SHOWING and the rows with data?
 
Upvote 0
Try;

<pre/>
Sub FilteredRow_Count()
Dim Area As Range
Dim Rowcount As Double

Rowcount = -1
'// [A1] is the start of your Filterer row
For Each Area In [A1].CurrentRegion.SpecialCells(xlVisible).Areas
Rowcount = Rowcount + Area.Rows.Count
Next

MsgBox Rowcount

End Sub

</pre>
 
Upvote 0

Forum statistics

Threads
1,214,617
Messages
6,120,541
Members
448,970
Latest member
kennimack

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