+ Reply to Thread
Results 1 to 5 of 5

Macro to copy text into autofilter criteria

  1. #1
    Registered User
    Join Date
    03-06-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    48

    Macro to copy text into autofilter criteria

    Hi everyone, I'm trying to figure out how I can set up the following.

    The end desire is to have something where my end user can type in the # they want details about and than click the shiny red button and BAM the macro sends them to the details page already filtered to the number they typed in before. When I recorded the macro however the paste into the criteria search box keeps recording as the text not the actual paste of the copied text from sheet 1. the macro comes up as follows.

    Range("J7").Select
    Selection.Copy
    Sheets("Sheet2").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _
    "47412"

    So essentially I'm just hoping to change the "47412" to .Paste (tried but just shot back an error to me.)

    Thanks in advance for any help.

    ~James H. Cameron
    Attached Files Attached Files
    Last edited by CDNcameron; 03-07-2012 at 04:57 PM.

  2. #2
    Registered User
    Join Date
    03-06-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Macro to copy text into autofilter criteria

    If "not possible" is the case feel free to point that out to me too.

  3. #3
    Registered User
    Join Date
    03-06-2012
    Location
    seattle, USA
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Macro to copy text into autofilter criteria

    Try the following.

    Sub CopypasteFilter()
    '
    ' CopypasteFilter Macro
    '

    '
    Dim filter_value As String

    filter_value = Range("J7").Value
    Range("J7").Select
    Selection.Copy
    Sheets("Sheet2").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _
    filter_value

    End Sub

    ---------------------------------------------------------------------------------------------------------------------------------------------
    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.
    Last edited by reddy14; 03-07-2012 at 04:27 PM.

  4. #4
    Registered User
    Join Date
    03-06-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Macro to copy text into autofilter criteria

    Works like a charm, thanks a lot for the direction. Got it working smoothly in the main file

  5. #5
    Registered User
    Join Date
    03-06-2012
    Location
    seattle, USA
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Macro to copy text into autofilter criteria

    You are welcome :-)

+ Reply to Thread

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