View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed[_9_] Ed[_9_] is offline
external usenet poster
 
Posts: 194
Default Macros with AutoFiltering

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
wrote in message
...
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.

On Fri, 16 Apr 2004 09:31:31 -0700, "K Dales"
wrote:

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

-----Original Message-----
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


.