That won't work since r will contain a range, so rows(r) will depend on
the value of the first cell in the range. It will also skip every other
row in a contiguous range of hidden rows.
Try:
Public Sub DeleteHidden()
Dim rRow As Range
Dim rDelete As Range
For Each rRow In ActiveSheet.UsedRange.Rows
If rRow.Hidden Then
If rDelete Is Nothing Then
Set rDelete = rRow
Else
Set rDelete = Union(rDelete, rRow)
End If
End If
Next rRow
If Not rDelete Is Nothing Then
Application.DisplayAlerts = False
rDelete.Delete
Application.DisplayAlerts = True
End If
End Sub
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.