Why doesn't this work then eh?

Mike Blackman

Well-known Member
Joined
Jun 8, 2007
Messages
2,494
Hi All,

Anyone have any idea why this doesn't work and can anyone think of any efficient ways of counting the number of hidden rows without looping through the usedrange?

Code:
wks.Columns.Count - wks.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count

FYI... the problem is that when there is are hidden row(s) its returning rows.count - the last row before the first hidden row.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I suspect it has more to do with the fact that you changed Columns.Count to Rows.Count at the start?
 
Upvote 0
Hi Rory,

My initial example code was flawed agree'd but the code I was physically working on wasn't (I don't think :) ).... Try this on a worksheet that has hidden rows.

Code:
Sub Test()

MsgBox Rows.Count - Columns(1).SpecialCells(xlCellTypeVisible).Rows.Count
MsgBox Rows.Count - Columns(1).SpecialCells(xlCellTypeVisible).Count

End Sub
 
Upvote 0
However it does work with cells not rows....

Code:
Sub Test()

MsgBox Rows.Count - Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count
MsgBox Rows.Count - Columns(1).SpecialCells(xlCellTypeVisible).Count

End Sub

Oh god my head hurts again!!!!
 
Upvote 0
I suspect Cells.count (or just Count as they are the same thing) works because it is unequivocal. Rows.Count only returns the number of rows in the first area presumably because of the possibility of overlap of rows - e.g. if your range encompassed different shaped ranges or ranges that started in different places. For example, if you had A5:A10 and C1:C9 selected, what would you expect rows.count to return?
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,504
Members
452,917
Latest member
MrsMSalt

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