Create Range of Visible Rows only

H

Humphrey

I would like to create a range containing only the visible rows in columns
A:N. I can filter the list and then create a range but it selects all the
hidden rows as well. Is there a way to restrict the range to just the
visible rows?

H
 
J

JLGWhiz

Assume the range is A1:C25

Sub testVis()
Dim rng As Range, c As Range
Set rng = ActiveSheet.Range("A1:C25")
For Each c In rng.SpecialCells(xlCellTypeVisible)
If c.Row.Hidden = True Then
MsgBox "Not Working"
Else
MsgBox "Working"
End If
Next
End Sub
You should get Working only when the macro runs.
 
J

JLGWhiz

Sorry Humphrey, left out a key word. Use this.

Sub testVis()
Dim rng As Range, c As Range
Set rng = ActiveSheet.Range("A1:C25")
For Each c In rng.SpecialCells(xlCellTypeVisible)
If Rows(c.Row).Hidden = True Then
MsgBox "Not Working"
Else
MsgBox "Working"
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top