Macros with AutoFiltering

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I have Autofiltering turned on, how can I tell from within a macro which
lines are selected?

for i = 1 to nRows
if row i is displayed then ....
next i
 
Check the row height - filtering just sets the height to
zero to hide the row.

For i = 1 to nRows
If Sheets(MySheet).Rows(i).RowHeight >0 Then...
Next i
 
Thanks for the reply. It answered the question and I got my code written.
However, I think I could have asked the question in a better way and
learned more. If I have autofiltering turned on, how can I write code to
acccomplish:

For each displayed row
Do something
Next displayed row

Thanks again.
 
This code increments down the visible cells in an AutoFiltered list. Wish I
could take credit, but I'm nowhere near that smart! Tom Ogilvy gave it to
me.

Sub Increment1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1(1).Select
End If
End Sub

Ed
 

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

Back
Top