Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XL97: Looping through filtered rows only 1

Status
Not open for further replies.

VBAjedi

Programmer
Joined
Dec 12, 2002
Messages
1,197
Location
KH
I have declared a range (CondRange) and set it to a worksheet range. The worksheet range has an autofilter applied to it, and I want to loop through all filtered/visible rows in CondRange. I thought the following would work, but it loops through ALL rows in CondRange (even the ones filtered out):
Code:
For Each C In CondRange.SpecialCells(xlCellTypeVisible)
  Debug.Print C.Row  
  ' Create running total of values in Cell next to C
Next C
What am I doing wrong?

Thanks!

VBAjedi [swords]
 

Try this :-

'-----------------------------------
Sub test()
Dim MyCondRange As Range
Set MyCondRange = Worksheets("Sheet1").Range("Condrange")
'-
For r = 1 To MyCondRange.Rows.Count
If MyCondRange.Rows(r).Hidden = False Then
Debug.Print r
End If
Next r
End Sub
'---------------------------------------


Regards
BrianB
** Let us know if you get something that works !
================================
 
VBAJedi - I know where you are going with this - this is for your ageing function isn't it ??
If that's the case, converting to a function won't work - specialcells method doesn't work in functions

Rgds
Geoff
Si hoc legere scis, nimis eruditionis habes
 
BrainB,

"...Rows(x).Hidden = True..." did the trick. Star for you!

xlbo,

Good guess! I wrote a UDF for my ageing issue. With the above snippet it works great. I'll post the working code in the other thread.

Thanks!

VBAjedi [swords]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top