Thread: Row Sequencing
View Single Post
  #4   Report Post  
Gary L Brown
 
Posts: n/a
Default

Hi Mark,
There are 3 possible answers but it depends on how you are hiding the rows.

1) If you are using Autofilter then the SubTotal() function will work.
=SubTotal(9,A1:A10) will sum only visible rows in the range A1 to A10
=SubTotal(3,A1:A10) will count only visible rows in the range A1 to A10

2) If you are MANUALLY hidding the rows AND you have Excel 2003, you can use
the new feature of the SubTotal() function...
=SubTotal(109,A1:A10) will sum only visible rows in the range A1 to A10

3) If you are MANUALLY hidding the rows AND you DO NOT have Excel 2003, you
need a macro to do this such as the one below.

'/=============================================/
Public Function Sum_Visible_Range(rng As Range) As Variant
'sum numbers in visible rows and columns only
Dim rngCell As Range
Dim varSum As Variant

Application.Volatile

varSum = 0

For Each rngCell In rng
If IsNumeric(rngCell.Value) = True Or _
IsDate(rngCell.Value) Then
If rngCell.EntireRow.Hidden = False And _
rngCell.EntireColumn.Hidden = False Then
varSum = varSum + rngCell.Value
End If
End If
Next rngCell

Sum_Visible_Range = varSum

End Function
'/=============================================/

HTH,
--
Gary Brown

If this post was helpful, please click the ''''Yes'''' button next to
''''Was this Post Helpfull to you?".


"Mark" wrote:

All I really want is the sum of all rows, since the number of the last row
reflects skipped rows. For example, last row says 2400, but it's actually
less since there are hidden rows. I want the actually number of rows
showing. Is there a simple way to get this?

"Gary L Brown" wrote:

Try this macro - select the range you want to put the numbers first and put
your starting number in the first cell of the selection.

'/=================================================/
Sub Row_List()
Dim rngCell As Range
Dim strAddress As String

strAddress = Selection.Range("A1").Address

For Each rngCell In Selection
If Hidden_Row(rngCell) = False Then
If strAddress < rngCell.Address Then
rngCell.Formula = "=" & strAddress & " + 1"
strAddress = rngCell.Address
End If
End If
Next rngCell

End Sub
'/=================================================/
Public Function Hidden_Row(rng As Range) As Long
'return 1 if row is hidden, 0 if row is visible
Application.Volatile

On Error Resume Next
Hidden_Row = 0

If rng.EntireRow.Hidden = True Then
Hidden_Row = 1
End If

End Function
'/=================================================/

HTH,
--
Gary Brown

If this post was helpful, please click the ''''Yes'''' button next to
''''Was this Post Helpfull to you?".


"Mark" wrote:

I have done a number of sorts and filters and rows now skip the numbers that
are hidden. Now I am satisfied with the rows showing and I want a straight
numerical sequence of the rows shown, without any numbers skipped. Can I get
this?