+ Reply to Thread
Results 1 to 12 of 12

Select filtered data using a macro

  1. #1
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Select filtered data using a macro

    Hi all, i have a table with headers in row 1 (A to Q).

    I need a macro to filter by column B (Date) to find selections for today only, and then copy the selections to past somewhere else.

    I don't want column A data to be included in the selected area (so only B to Q), and sometimes there will be only 1 item, sometimes 0, sometimes 100 - so the amount of rows to be selected is unknown.

    Any help much appreciated - as I suspect someone will know exactly how to do this

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Select filtered data using a macro

    Hi look into attachment and tell is it ok if not prepare the sample
    Attached Files Attached Files
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Select filtered data using a macro

    Hi Tom, your data set is fine - however the macro gives an error on
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Select filtered data using a macro

    This code works but only one time
    try this

    Please Login or Register  to view this content.
    Of course You have to adjust this to your needs
    Last edited by tom1977; 05-29-2012 at 04:10 AM.

  5. #5
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Select filtered data using a macro

    Hi Tom, I don't understand what you mean adjust to my needs?

    I can't get this coding to do anything

  6. #6
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Select filtered data using a macro

    Ok try attachment again
    In previous post I have said that You can change my code whatever You wants because I do not know how your file looks like
    Attached Files Attached Files
    Last edited by tom1977; 05-29-2012 at 04:59 AM.

  7. #7
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Select filtered data using a macro

    Hi Tom, appreciate your response but the macro wont run - it just flags an error (run time 1004 - auto filter method of range class failed) at

    Range("A1:Q" & last).AutoFilter Field:=2, Operator:=xlFilterValues, Criteria2:=Array(2, Now())

    So I am not sure how to change the code as it doesn't work for me to begin with

  8. #8
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Select filtered data using a macro

    On my computer it works (did you check this on my file or your?). If you try to use this on your file mayby sand the sample?

  9. #9
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Select filtered data using a macro

    Hi Tom, please see the attached example.

    I just want to filter to select "row 7 in this insatnce" B7:Q7 and paste to sheet 2 A1

    The macro needs to skip if there are no selections that meet "today" in column B.
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Select filtered data using a macro

    Check this on your file
    Please Login or Register  to view this content.
    Last edited by tom1977; 05-29-2012 at 06:34 AM.

  11. #11
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Select filtered data using a macro

    Hi Tom, still get an error on code part
    .Range("A1:Q" & last).AutoFilter Field:=2, Operator:=xlFilterValues, Criteria2:=Array(2, Now())

  12. #12
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Select filtered data using a macro

    hi cmb80, option, run code "test"

    PS. You post files with .xls extension which usually means the person uses Excel 2003. Your profile says Excel 2007. This discrepancy can cause problems because autofilter syntax is different in those versions.
    Attached Files Attached Files
    Last edited by watersev; 05-29-2012 at 08:24 AM.

+ 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