+ Reply to Thread
Results 1 to 15 of 15

filtering data if have X value, if not then filter with Y

  1. #1
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    filtering data if have X value, if not then filter with Y

    Hi,

    i have the following code

    Please Login or Register  to view this content.
    What I want is, by clicking on the CartCType button, the macro will check in columns A if it contain 10*...if it does, then filter it with only this criteria 10_C*

    if it does contain 20, then filter if with 20_C*

    Any help??
    Last edited by extremis; 08-15-2013 at 02:15 PM.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: filtering data if have X value, if not then filter with Y

    Please Login or Register  to view this content.
    you're filtering the whole column? It will only filter by the last value found. Would you like to exit the sub once the first value is found?
    Last edited by Solus Rankin; 08-15-2013 at 08:35 AM.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: filtering data if have X value, if not then filter with Y

    Well..i am filtering from A2 to D2 to the bottom..but as the first value is found, it should solve the problem as before i have a macro that will select let say, all the 10...or all the 20...

    so, it look a bit like that on my excel sheet

    10_C03
    10_C05
    etc...etc..
    10_R01

    Also, I tried the macro...it said name argument not found and it highlight in yellow the

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: filtering data if have X value, if not then filter with Y

    Sample.xlsmany clue why?....here a sample of the data..see the files!

  5. #5
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: filtering data if have X value, if not then filter with Y

    help lol..

    I cant seem to make it work

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: filtering data if have X value, if not then filter with Y

    You don't have a with statement on your autofilter. It needs to be .cells.autofilter...
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: filtering data if have X value, if not then filter with Y

    I do not know what is the purpose of the code.
    Why do you need an if statement and a loop? And after a filter is found, what is the purpose- loop in to next row? What happens to the filtered data then?

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: filtering data if have X value, if not then filter with Y

    Thats why I asked if you need to exit sub. Its just going to filter it again when it gets to the next line. What you'll end up is column A filtered by the last value found in the loop.

  9. #9
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: filtering data if have X value, if not then filter with Y

    has you can see with the file i attached. What I want is..when I will click on 10, it will filter all the 10..then..when i click on C..it will filter all the C on the already filtered list....which mean, all the 10_C*
    then at last, when I will click 1, it will filter the already filtered 10 and C and will only filter the 01...which will have for result 10_C_01

    another example: If i click on the 20, it will select all the 20...then, if i click on the R...it will filter all the R that are in the 20..so it will look like 20_R*...then, if i want to see all the number 10...it will filter The 20_R_10..

    Button click order are selection of the group 10-90 (green button)
    Then selection of the Type (mixed, R, Other, MP, C, etc)(Orange button)
    and selection of the number 1-96 (Blue button)

    I tried to build a macro and make it work..but i got stuck at the second "filtration"

  10. #10
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: filtering data if have X value, if not then filter with Y

    i am sorry..i am learning VBA by myself...and i am not a pro..am at the point where i can take code, play with it, modify it and make it work..but sometime it look a bit messy

  11. #11
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: filtering data if have X value, if not then filter with Y

    I also had this one...but it doesnt work -_-....

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: filtering data if have X value, if not then filter with Y

    so what do you think guys?

  13. #13
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: filtering data if have X value, if not then filter with Y

    Xero, I was able to make it work..i am sorry, I had a hard time understand what you said, it seem there was a part missing..here is the code:

    Please Login or Register  to view this content.
    now for your asnwer, there is no need to be a loop since it<s the first column that is filter..damn i am dumb...THANKS for your helps

  14. #14
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: filtering data if have X value, if not then filter with Y

    Glad you got it figured out.

  15. #15
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: filtering data if have X value, if not then filter with Y

    i added to your rep guys!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 9
    Last Post: 07-02-2020, 11:48 AM
  2. Date Filter is not working, beside filtering data also needs some help.
    By sanc.jobs2012 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-14-2012, 05:51 AM
  3. Replies: 3
    Last Post: 05-15-2011, 11:46 AM
  4. Replies: 0
    Last Post: 08-24-2010, 06:51 PM
  5. Filtering Data & Auto-filter
    By Henry c in forum Excel General
    Replies: 10
    Last Post: 05-07-2010, 09:15 PM

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