|
-
Sep 4th, 2005, 11:00 AM
#1
Thread Starter
Frenzied Member
Resolved - How to count the number of rows except hidden rows?
I have some sort of data on my excel sheet in 30 rows. Let say A1 to A30.
Here some rows were hidden. Let say A5 to A8 totally 4 rows were hidden. I just want to count the number of rows except hidden rows.
I just tried the following code.
VB Code:
MsgBox ActiveSheet.UsedRange.Rows.Count
This code counts the all row which are used in active sheet. The above code gives the answer 30. but my answer should be 26 not 30.
Thanks in advance!
CS.
Last edited by cssriraman; Sep 4th, 2005 at 09:12 PM.
-
Sep 4th, 2005, 11:11 AM
#2
Lively Member
Re: How to count the number of rows except hidden rows?
How about a function to get it:
VB Code:
Option Explicit
Public Function COUNTVISIBLE(rng As Range) As Integer
' Counts visible cells
Application.Volatile True
Dim rcount%
Dim r As Range
rcount = 0
Set rng = Intersect(rng.Parent.UsedRange, rng)
For Each r In rng
If Not r.EntireRow.Hidden And _
Not r.EntireColumn.Hidden Then _
rcount = rcount + 1
Next r
COUNTVISIBLE = rcount
End Function
-
Sep 4th, 2005, 07:10 PM
#3
Re: How to count the number of rows except hidden rows?
Thats nice Justin, but how about all in one line of code? 
VB Code:
Option Explicit
Public Function CountMe()
CountMe = ActiveSheet.Range("A1:A30").Cells.SpecialCells(xlCellTypeVisible).Count '=26
End Function
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 4th, 2005, 09:03 PM
#4
Thread Starter
Frenzied Member
RESOLVED - Re: How to count the number of rows except hidden rows?
Rob, That's great! Thanks a lot!
 Originally Posted by RobDog888
Thats nice Justin, but how about all in one line of code?
VB Code:
Option Explicit
Public Function CountMe()
CountMe = ActiveSheet.Range("A1:A30").Cells.SpecialCells(xlCellTypeVisible).Count '=26
End Function
Once again Thanks,
CS.
-
Sep 4th, 2005, 10:49 PM
#5
Lively Member
Re: Resolved - How to count the number of rows except hidden rows?
As long as the user doesn't have all rows from 1-30 hidden, (serious longshot) and doesn't use it like a formula in a cell, looks very nice.
-
Sep 4th, 2005, 11:14 PM
#6
Re: Resolved - How to count the number of rows except hidden rows?
Correct. Thanks, but its the best there is for the range but if there is a need for an entire row then Justin has it hands down.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|