Consulting

Results 1 to 6 of 6

Thread: Solved: Visible Range after AutoFilter

  1. #1
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location

    Solved: Visible Range after AutoFilter

    How would I determine the visible range is after executing an Autofilter command? For Instance, after AutoFilter, only rows 200 - 250 are showing.... How do I use a loop to go thru those rows that I want to perform actions on....

    [vba]
    For loop = FirstVisibleRow to LastVisibleRow
    [do work]
    Next
    [/vba]

    How can I tell that row starts at 200 and end at 250

    Just have a thought, what if I only wanted to act on rows that are visible, non-contiguous
    Thanks

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    set your range to the visable cells maybe:
    [VBA].SpecialCells(xlCellTypeVisible)[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Thank you Lucas, this got me started and I think that I am close, I may need another push to get going
    [VBA]
    Set VisibleRange = ActiveSheet.Cells.SpecialCells(xlCellTypeVisible)
    [/VBA]

    now, when I do a print on VisibleRange.Address, it gives me 3 ranges,
    $1:$1 - my header row
    $200:$250 - this is what I want to home in onto
    $251:$65536 - practically no data afterward

    I can parse the $200:$250, now to me this is "static" because that I am picking on the 2nd set of data, what if next time the VisibleRange returns a wack of ranges, how do I determine how many that I should go thru? I hope that I am making sense.....

    Thanks.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    you could try playing with[vba]For rw = 2 To 500
    If Not Rows(rw).Hidden Then
    MsgBox rw & " is a visible row"
    End If
    Next rw[/vba]or[vba]For Each rw In Intersect(UsedRange.Columns(1).SpecialCells(xlCellTypeVisible), Range("A2:A500"))
    MsgBox rw.Row & " is a visible row"
    Next rw[/vba]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    example of selecting visible cells after filtering attached......I'm sure it will help you understand. It excludes the header row.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Thank you all, this solved my problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •