Consulting

Results 1 to 4 of 4

Thread: getting the row numbers of visible rows in an filtered selection

  1. #1
    VBAX Newbie
    Joined
    Oct 2012
    Posts
    2
    Location

    Unhappy getting the row numbers of visible rows in an filtered selection

    Hello all,

    I have an Excel 2007 table which has 1500 rows and 60 columns of data. I use autofilter to filter out some information. For example I have filtered row 5, 12, 12 and 18. I select some rows (row 5 and 12)
    I need a macro to find out the row numbers of these selected rows.

    Thanks in advance.

    catgreen

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    [VBA]Sub blah()
    For Each rw In Selection.Rows
    If Not rw.Hidden Then MsgBox rw.Row
    Next rw
    End Sub
    [/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.

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    I'm not sure what you want to do with those row numbers (put them in an array?, add them? ..), but some variation of this should work.

    [VBA]With Selection
    If .Cells.Count = 1 Then
    MsgBox .Address
    Else
    MsgBox .SpecialCells(xlCellTypeVisible).Address
    End If
    End With[/VBA]

  4. #4
    VBAX Newbie
    Joined
    Oct 2012
    Posts
    2
    Location
    Sorry for my late response, this solution worked problem free thank you.

Posting Permissions

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