Results 1 to 12 of 12

Random Selection of Row Numbers from a Filtered Range

Threaded View

  1. #1
    Valued Forum Contributor Saarang84's Avatar
    Join Date
    02-19-2009
    Location
    Chennai, India
    MS-Off Ver
    XL 2003 to 2010
    Posts
    812

    Random Selection of Row Numbers from a Filtered Range

    Hi,

    I'm trying to get only the row numbers from a filtered range. These row numbers should be stored in an array which will be used later in the code and should exclude the header row.

    Below is the code that i tried out. There are 2 different types of msgbox statements which i tried (refer msgbox statements just before the end Sub statement) alternatively (by commenting one of them at a time).

    rngVisible.Address gives me the entire filtered range
    rngVisible.Row gives me the only one individual row number (1st row number in the filtered range)


    Sub Filtered_Rows()
    Dim rngFilter As Range
    Dim rngVisible As Range
    'is there an autofilter on sheet1?
    If Sheet1.AutoFilterMode Then
        'are any filters being used?
        If Sheet1.FilterMode Then
            'get a reference to the autofilter range
            'excluding the header row
            With Sheet1.AutoFilter.Range
                Set rngFilter = .Offset(1).Resize(.Rows.Count - 1, .Columns.Count)
            End With
        End If
    End If
    If rngFilter Is Nothing Then
        MsgBox "no filtering is being applied!"
    Else
        'find the visible cells, if there are none then an error will be raised
        On Error Resume Next
        Set rngVisible = rngFilter.SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
        If rngVisible Is Nothing Then
            MsgBox "there are no visible cells!"
        Else
        ' below msgbox statements to be used alternatively one at a time
            MsgBox rngVisible.Row
            MsgBox rngVisible.Address
        End If
    End If
    End Sub

    How to get only the visible row numbers and store them in an array??
    Sample workbook attached.

    Sarang
    Attached Files Attached Files
    Last edited by Saarang84; 09-12-2010 at 01:25 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1