+ Reply to Thread
Results 1 to 13 of 13

AutoFilter Macro

  1. #1
    Registered User
    Join Date
    10-06-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    30

    AutoFilter Macro

    Hello Community,

    I've recently created a macro that filters a data set, copy's it, and then pastes it to another tab.

    How to filter the data is read by a validated cell that has a drop down list. You select the components you want to filter and then press the macro button.

    My problem arises that I have three categories to search by: Currency, Year, And Date for example My macro forces me to write a value in each one. So I can't pull up only a certain currency because if I leave the others blank the "filter" fails because there is no blank data set.

    Any thoughts on how to fix this?

    Here is the Macro:

    Please Login or Register  to view this content.
    Public Sub FilterCRNCY()

    Sheets("Style 2").Select
    Selection.AutoFilter Field:=7, Criteria1:=Range("D3").Value


    Selection.AutoFilter Field:=8, Criteria1:=Range("D4").Value

    Selection.AutoFilter Field:=, Criteria1:=Range("D5").Value





    Range("A9:P11826").Select
    Selection.Copy
    Sheets("Data").Select
    Range("A2").Select
    ActiveSheet.Paste

    'Erases filters:

    Sheets("Style 2").Select
    Selection.AutoFilter Field:=7
    Selection.AutoFilter Field:=8
    Selection.AutoFilter Field:=3


    Sheets("Data").Select



    End Sub
    Please Login or Register  to view this content.
    Last edited by cocolete; 12-12-2011 at 06:14 PM.

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: AutoFilter Macro

    Put code tags around your code , it is the # on advanced edit. And can you post a dummy work book?
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    10-06-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: AutoFilter Macro

    Hope this is what you meant:


    Please Login or Register  to view this content.
    Public Sub FilterCRNCY()

    Sheets("Style 2").Select
    Selection.AutoFilter Field:=7, Criteria1:=Range("D3").Value


    Selection.AutoFilter Field:=8, Criteria1:=Range("D4").Value

    Selection.AutoFilter Field:=, Criteria1:=Range("D5").Value





    Range("A9:P11826").Select
    Selection.Copy
    Sheets("Data").Select
    Range("A2").Select
    ActiveSheet.Paste

    'Erases filters:

    Sheets("Style 2").Select
    Selection.AutoFilter Field:=7
    Selection.AutoFilter Field:=8
    Selection.AutoFilter Field:=3


    Sheets("Data").Select



    End Sub
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by cocolete; 12-06-2011 at 08:27 AM. Reason: Corrected Code Tags

  4. #4
    Registered User
    Join Date
    10-06-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: AutoFilter Macro

    Here is the attachement.
    Attached Files Attached Files

  5. #5
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: AutoFilter Macro

    Can you edit your post and add code tags to both your posts. Unfortunately these are forum rules and I can't post a reply until you do.
    Cheers

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: AutoFilter Macro

    Please wrap your code in code tags as per rule #3 of the forum rules, as JapanDave has stated, you will not be helped until you follow the forum rules. Thank you.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

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

    Re: AutoFilter Macro

    @ To All members and Mods

    Please be advised since the forum has ben updated, there are still some problems. One of which is the horizontal scroll bar in the Code window is not working. If you find that your code is wider than the Code widow, remove the code tags. This will make your post readable. This should be corrected sometime tomorrow.
    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!)

  8. #8
    Registered User
    Join Date
    10-06-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: AutoFilter Macro

    Apologies....I've put in the tags on my codes

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

    Re: AutoFilter Macro

    hi cocolete, please check attachment, select values for autofilter in C3;C4;C5 on Sheet("2009 - 2011 (2)") or leave some of them empty and press Start button
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    10-06-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: AutoFilter Macro

    This is AWESOME thank you very much.

    Just to understand it: How did you get the macro to link to the "Start" button?

    Usually I create the "command button" and the link the macro in VBA. When I went to look for it in the sheets I didn't find it.

    Regards,

    Daniel Roman

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

    Re: AutoFilter Macro

    you used ActiveX panel to add your button and I used Forms to add mine. To assign a code to it just right click, select assign macro.

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

    Re: AutoFilter Macro

    if you are satisfied with the help provided, please mark the thread as Solved, see Forum Rules for details, Rule #9:

    Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.
    Last edited by watersev; 12-06-2011 at 06:03 PM.

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

    Re: AutoFilter Macro

    file reposted on request
    Attached Files Attached Files

+ 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