+ Reply to Thread
Results 1 to 19 of 19

VBA code for filtering results

  1. #1
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    VBA code for filtering results

    Hi guys,
    I have a question. I want to select all "id"s from column A that has all three results next to it in column B e.g. breakfast, lunch, supper. and count them in cell C2. Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA code for filtering results

    Hi batya,
    try this
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    Re: VBA code for filtering results

    This seems to be working on this simplified table.Can you help with this code on this attachment. But this time it is "id" from column B and results from column H and count them in cell P2. Thanks again!
    Attached Files Attached Files

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA code for filtering results

    try it
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    Re: VBA code for filtering results

    It is working but when i execute the code it also counted 'id'=89 also but it has not got all three results e.g ertirlik, oylan nahar, agsam nahar next to it (from column H). instead it has two ertirlik and 1 agsam nahar. does it count only matching "id"s and give result or counts using conditions i gave above? Thanks

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA code for filtering results

    then try this
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    Re: VBA code for filtering results

    you are amazing. can you help me with highlighting the "id"s like it was in previous version (i can't check the results) . Also if you have time. Is it possible to count separately these variables e.g ertirlik, oylan nahar, agsam nahar and write result in cell P3, P4 and P5. Thanks a lot

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA code for filtering results

    Try
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    Re: VBA code for filtering results

    it does not work as intended it should give separate counts of these variables "ertirlik", "oylan nahar", "agsam nahar" in cells P3, P4 and P5. manually counted result should be as this: 52,130,84

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA code for filtering results

    Are they just count each meal?
    Please Login or Register  to view this content.
    Total are the rows that have 3 meals together.
    Last edited by jindon; 06-18-2019 at 04:55 AM.

  11. #11
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    Re: VBA code for filtering results

    yes kind sir. the 3 three counts for meals are correct but as for a counting the "id"s that have three (ertirlik, oylan nahar, agsam nahar) result next to it in column H, it gives result 87. which is correct if it counts all highlighted cells. 87/3=29 but it should be 28. i think it is because some "id"s have double "ertirlik"s. the one that user "nilem" wrote gave me the correct result. can u combine his code (including the function to "highlight IDs") and yours which counts meals separately? thanks in advance!

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA code for filtering results

    Is this how you wanted?
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    Re: VBA code for filtering results

    i'm sorry Mr. Jindon i think your first reply is exactly what i want. and everything seems to work fine. Thanks again guys for your time. You guys are best. I hope i didn't take much of your time.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA code for filtering results

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  15. #15
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    Re: VBA code for filtering results

    One last question. I've protected the worksheet with password but VBA code won't execute if it is protected. what can i do about it? is it possible to add somewhere in below code so that it unprotect it in the beginning and protects again at the end!
    Please Login or Register  to view this content.

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA code for filtering results

    Add 2 lines in bold
    Please Login or Register  to view this content.
    change "Password" to actual one or just delete it if no password used.

  17. #17
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    Re: VBA code for filtering results

    i tried it still gives me error 1004. when i debug it highlights this area
    Please Login or Register  to view this content.
    Last edited by batya; 06-18-2019 at 07:27 AM.

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: VBA code for filtering results

    OOps... of course..
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    08-02-2014
    Location
    Ashgabat, Turkmenistan
    MS-Off Ver
    2013
    Posts
    23

    Re: VBA code for filtering results

    now it works. thanks for your time.

+ 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. VBA code for filtering the data and sending results to the concerned departments.
    By R4Rifi in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-25-2017, 06:20 AM
  2. [SOLVED] Filtering Top 10 Results Based on 2nd Column
    By newbieexceldude in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-13-2017, 03:33 PM
  3. Help with =INDEX 'breaking' when filtering results.
    By barryweston in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-05-2015, 11:06 AM
  4. Question about filtering out results in a macro?
    By Torvald in forum Excel General
    Replies: 0
    Last Post: 07-30-2014, 01:15 PM
  5. Filtering and displaying results
    By aletukas in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-21-2013, 04:42 PM
  6. Listbox filtering results
    By brouhaha501 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2010, 02:18 PM
  7. Displaying Search results (filtering?)
    By Klok in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-04-2009, 06:45 AM

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