Hi,
I'm trying to get only the row numbers from a filtered range. These row numbers should be stored in an array which will be used later in the code and should exclude the header row.
Below is the code that i tried out. There are 2 different types of msgbox statements which i tried (refer msgbox statements just before the end Sub statement) alternatively (by commenting one of them at a time).
rngVisible.Address gives me the entire filtered range
rngVisible.Row gives me the only one individual row number (1st row number in the filtered range)
Sub Filtered_Rows()
Dim rngFilter As Range
Dim rngVisible As Range
'is there an autofilter on sheet1?
If Sheet1.AutoFilterMode Then
'are any filters being used?
If Sheet1.FilterMode Then
'get a reference to the autofilter range
'excluding the header row
With Sheet1.AutoFilter.Range
Set rngFilter = .Offset(1).Resize(.Rows.Count - 1, .Columns.Count)
End With
End If
End If
If rngFilter Is Nothing Then
MsgBox "no filtering is being applied!"
Else
'find the visible cells, if there are none then an error will be raised
On Error Resume Next
Set rngVisible = rngFilter.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rngVisible Is Nothing Then
MsgBox "there are no visible cells!"
Else
' below msgbox statements to be used alternatively one at a time
MsgBox rngVisible.Row
MsgBox rngVisible.Address
End If
End If
End Sub
How to get only the visible row numbers and store them in an array??
Sample workbook attached.
Sarang
Bookmarks