counting non hidden rows in VBA

fraz627

Board Regular
Joined
Apr 26, 2014
Messages
99
Office Version
  1. 2010
Platform
  1. Windows
After filtering a worksheet I would like to sequentially number each row for the non hidden rows

row status
1 visible 1
2 hidden
3 hidden
4 visible 2
5 visible 3

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Seeing as you haven't said anything about where your data is. The below is based on data being in column A and the result in column B (amend to suit).
Code:
Sub NumVis()
    Dim myCell As Range, x As Long
    x = 1
    Application.ScreenUpdating = False
    For Each myCell In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(12)
        myCell.Offset(, 1).Value = x
        x = x + 1
    Next
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
As an alternative........the result is in Col B.

Code:
Sub visible_rows()

Dim lr As Long


lr = UsedRange.Rows.Count
Count = 1
For y = 1 To lr Step 1

    If Rows(y).Hidden = False Then
    
        Cells(y, 2).Value = "Visible" & Count
        Count = Count + 1
     End If
     
Next y

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,956
Members
448,535
Latest member
alrossman

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