+ Reply to Thread
Results 1 to 3 of 3

Filter to bottom of data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Filter to bottom of data

    I usually use the macro recorder to get code like this:

    ActiveSheet.Range("$A$1:$C$39").AutoFilter Field:=2, Criteria1:= _
            "Sandra Loya"
    When I run the macro, the data will vary in length, so I must change the bottom cell reference. So far I have just changed it to be a really low cell so that it will always cover a larger range than my data.

    ActiveSheet.Range("$A$1:$C$8000").AutoFilter Field:=2, Criteria1:= _
            "Sandra Loya"
    But is there an easy way to have the macro automatically reset the range to the bottom of the current data? Something like this:

    ActiveSheet.Range("A1.CurrentRegion").AutoFilter Field:=2, Criteria1:= _
            "Sandra Loya"

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Filter to bottom of data

    Hi, Jiptastic,

    mabye
    ActiveSheet.Range("A1").CurrentRegion.AutoFilter Field:=2, Criteria1:= _
            "Sandra Loya"
    or
    With ActiveSheet
      .Range("$A$1:$C" & .Cells(Rows.Count, "C").End(xlUp).Row).AutoFilter Field:=2, _
          Criteria1:="Sandra Loya"
    End With
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Filter to bottom of data

    Hello Jiptastic,

    You were close. The code would be as below...
    ActiveSheet.Range("A1").CurrentRegion.AutoFilter Field:=2, Criteria1:= "Sandra Loya"
    However, there a couple of points to remember. The current region must be contiguous. A blank row or column defines the end of the region. The region must include cell A1 and must have at least 2 columns in the region.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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