PDA

View Full Version : Loop through auto generated filter by variable (Help needed!)



j.smith1981
03-31-2009, 08:35 AM
I am making an auto generating filter, by a variable.

What I am wanting it to do, pritty basic really, is select the first row of viewable data.

Loop down one column say the 1st column (1,1) then select the next until the viewable cells are empty.

Its not doing this at present its selecting the first row and it looping asif the rows where there with data in them through the entire sheet, not just the viewable rows, all 700 of them.

Does anyone know an exact way of making it loop through just the viewable cells please?

Thank you,
Jez

AZIQN
03-31-2009, 09:55 AM
I believe there are a few different ways of doing this, depending on what you want to do with it afterwards...but here is one that I have used:


Dim LastRow as Long
With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1

'(Insert your filter, If statement, or whatever it is you need it to do)

Next i
End With

This code will count the rows in column A, then perform the loop on the last row and work up the sheet until it reaches row 1.
Hope this helps.