+ Reply to Thread
Results 1 to 22 of 22

Hide and Autofilter Macro based on Criteria

  1. #1
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Hide and Autofilter Macro based on Criteria

    I am attempting to create a Macro that will look at cell I3 and if it = "GBP" then it will do the following

    Please Login or Register  to view this content.
    and if blank it don't do anything

    I will admit I used the "Record Macro" to obtain the code shown above. I am unsure how to insert the criteria so that the autofilter macro knows to look to cell I3 and based on whether it is USD or GBP will perform the appropriate macro.

    I have gone thru what I believed were similar posts and can't seem to get past this part. Macro Newbie here but learning everyday! I'm sure I'm close just not close enough
    Attached Files Attached Files
    Last edited by romperstomper; 09-22-2010 at 06:52 PM. Reason: mark solved
    Dawn - Guru in Training

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Hide and Autofilter Macro based on Criteria

    Sorry, but:

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    Hope this worked, sorry about that, first time I did the "code" thing

  4. #4
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Hide and Autofilter Macro based on Criteria

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    I copied pasted your code but there seems to be a problem because it won't stop running. I end up having to go to the Task manager and end the program. I suspect the problem to be an open end compile? I have attempted to "fix" the code but because I am such a novice, I appear to be getting it wrong. Do I need to put in a macro for 0 or "" in the Currency Value field? I was hoping that if I3 = 0, then just autofilter Col P first then Col B (Sorry should have stated that in my original question) PS your version looks cleaner than mine. I am trying to learn this foreign language called VBA!
    Last edited by dawnmau; 09-20-2010 at 01:06 PM.

  6. #6
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    Still looking for help to get this finished up so I can close it out!

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Hide and Autofilter Macro based on Criteria

    Do you mean just:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    Yes but that's not the whole code is it? I mean how do I incorporate that logic with the previously written code? I need specific columns hidden based on the value in I3 and then I need Column P is filtered 1st then Column B is filtered. But if you can simplify the code based on these parameters I would really appreciate it. I am trying to understand how VBA works by looking at the relationships cause and effect of the codes written. Thanks for taking the time to teach this Guru wannabe!
    Last edited by dawnmau; 09-22-2010 at 10:28 AM.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Hide and Autofilter Macro based on Criteria

    Based on your question, that code checks I3 and then calls whichever of your two posted macros is appropriate. I'm not sure what else you want.

  10. #10
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    Sorry for being so dense here, but I don't know what I am suppose to do with the code you provided. Do I copy/paste after "next i" at the bottom? or is your code replacing the code previously written and if so how do I tell the "code" which columns to hide based on criteria? I feel like I am Japan and I don't have a translator to help figure out what the signs mean when it comes to VBA. I would like to get a book that effectively explains VBA without putting me to sleep or causing my eyes to roll to the back of my head. (I had that problem studying Audit for the CPA exam)

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Hide and Autofilter Macro based on Criteria

    No, my code is in addition to the code you posted. If you run the code I posted, it checks the value of I3 and then runs whichever of your two original routines is appropriate.

  12. #12
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    At the risk of appearing like an idiot (and apparently when it comes to VBA I am) Could you please show me what you mean. As a hearing impaired individual I rely on visual demonstrations to fully comprehend what someone is saying. I have tried to do what I think you are saying but I keep getting errors

    Please Login or Register  to view this content.
    And I really do appreciated your time re: this and I am sure this is frustrating from your end.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Hide and Autofilter Macro based on Criteria

    Why have you altered the original macros? I assumed they already did what you wanted, in which case you just add my code (separate from the two subs you already had) and then run it.

  14. #14
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    Please see post #5 & #6. JieJenn posted #4 but never responded to my subsequent posts. In the process I was trying to work it out but have been unsuccessful and when I failed to get a response I contacted you (because you chided me for not following the rules, which upon realizing my error I quickly complied) in the hopes of what my recourse in resolving my macro issues were. I really want to learn VBA but this really isn't something you can quickly pick up on the fly, at least I haven't been able to. Microsoft help in this area has been inadequate which is why I always turn to the ExcelForum. Please forgive my inexperience in trying to tackle this macro as I am trying to do multiple things with one macro. Would it be possible for you to help me or is there someone else I would be better off asking? I feel I have taken up so much of your time and I was unaware of the miscommunication gap in trying to resolve this issue. As I am a visual learner I try to take the codes I am given and deconstruct and understand the code but I am not always successful but I am not good with "word" problems as you can see.

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Hide and Autofilter Macro based on Criteria

    Let's go back to the beginning so we are on the same page.

    Did your original two macros do everything you wanted each of them to do?

  16. #16
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    No, it kept running and I had to do a task manager to exit out it. And thanks so much for starting with clean slate!

  17. #17
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Hide and Autofilter Macro based on Criteria

    I thought that happened when you used JieJenn's code? I'm asking about the code you originally posted?

  18. #18
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    Yes but only if I did 1 at a time. I did a "Record Macro" and pasted the two together but couldn't figure out how to "write" the code to search for the condition which is what led me to this fine forum to request help.

  19. #19
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    I did it I did it I did it!!!, Ok after realizing you were using my original macros I thought I would give it one more shot and Voila!! I got it to work!! Now that I see how it plays out I am not going to create a button that will "Unhide" All (Added a button to process the macro and tested it and it appears to be working as it should.) For your viewing pleasure here is my code

    Please Login or Register  to view this content.
    :D

  20. #20
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Hide and Autofilter Macro based on Criteria

    OK, well what I was suggesting is you have three macros (your original two and the one I posted) and the one you run (HideSomeColumns) will then run one of the other two if applicable:

    Please Login or Register  to view this content.
    Does that do what you want?

  21. #21
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Hide and Autofilter Macro based on Criteria

    Looks like I should have refreshed when I got back to my computer! Good work.
    (I removed some unnecessary scrolling in my version - you may wish to do the same)

  22. #22
    Registered User
    Join Date
    03-04-2010
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007, Excel 2010, Excel 2003
    Posts
    87

    Re: Hide and Autofilter Macro based on Criteria

    Thanks, I will do that! I really do appreciate your patience and help, it has been to say at the very least, educational! Now I can close this puppy out and mark it resolved!

+ 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