Hi,
How can I determine the amount of rows in a subtotal range collapsed to level 2
My variable counts one row where i have 5 rows in my collapsed subtotal range
myRC = Range("A3").CurrentRegion.Offset(1, 0).Resize(Range("A3").CurrentRegion.Rows.Count - 2).SpecialCells(xlCellTypeVisible).Rows.Count
Any ideas?
TX
Count SubTotal Rows
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Count SubTotal Rows
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78629
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Count SubTotal Rows
When you collapse the range, the visible cells consist of several areas. The expression .Rows.Count returns the number of rows in the first area only.
You have to sum the number of rows over all areas:
You have to sum the number of rows over all areas:
Code: Select all
Dim rngTotal As Range
Dim rngArea As Range
Dim myRC As Long
Set rngTotal = Range("A3").CurrentRegion
Set rngTotal = rngTotal.Offset(1, 0).Resize(rngTotal.Rows.Count - 2).SpecialCells(xlCellTypeVisible)
For Each rngArea In rngTotal.Areas
myRC = myRC + rngArea.Rows.Count
Next rngArea
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Count SubTotal Rows
That makes sense. Thanks for that clarifying explanation.
It works well TX :)
It works well TX :)
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.