+ Reply to Thread
Results 1 to 30 of 30

Count Based on Criteria

  1. #1
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Count Based on Criteria

    Hi

    I have a workbook with a few sheets. I need the cells on sheet 1 to be auto populated from sheet 2. I need the data to search for each date (Row 1, sheet 1) on sheet 2. Then search for each course (Column A, Sheet 1) within the specified date range on sheet 2.

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    "Then search for each course (Column A, Sheet 1) within the specified date range on sheet 2. "
    and when you found it what do you want to do?
    e.g. TR002803 for 23 January
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    I need it to populate the associated cell in Sheet 1 with the total count of each course for that day. There may be multiple instances of the course on the same day.

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    It means for our example
    e.g. TR002803 for 23 January
    The result is 1 ?

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    I was wrong because dates don't match.
    Can you give an example of the result you want

  6. #6
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    That would be correct. If the particular course was taught twice it would return 2 etc.

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    See file attached.
    Take care that it needs an empty cell at the end of the date data set to make the limit between 2 dates.
    Attached Files Attached Files
    Last edited by PCI; 08-26-2014 at 02:43 AM.

  8. #8
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    Thanks

    This looks like it will work. I can't seem to get it to run in my other spreadsheet though. I am sure that it is something simple, but I can't figure it out.

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    Did you care to have an empty cell to shown the end of the data.
    Just to explain how the function is working:
    =SearchCourses(Course,Date,Range)
    It looks in the Range for the Date and when found it, scrolls down until to find an empty cell counting the number of times Course exists
    Else send a new file with the issue

  10. #10
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    Yes, I inserted the blank cells. The issue that I am having is executing the code. I copied the code to my spreadsheet, but am not sure how to get it to run. With previous uses of code, I inserted it into a userform that activated it. How do I get it to run to populate?

    Thanks

  11. #11
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    It's a User Define Function.
    Put the function code in a module
    And then in sheet1 where there is the date and the courses reference put
    =SearchCourses($A2,V$1,Sheet2!$A$1:$E$19)
    A2 = course reference
    V1 = date
    Sheet2!$A$1:$E$19 = range where is the data
    Afterwards if you prefer to have a macro launched by a button, a key tell it.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    I still can't get this to work. I opened the attached sheet called courses. I tried to add another course to sheet 2 and when I go back to sheet 1 all of the cells are 0. They will not update. Thoughts?

  13. #13
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    Can you send the file with the issue?
    Or using the file attached explain step by step what you did.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    I enabled macros and added a new course to Jan 21. When I go back to sheet 1. It is all zeros.

    Thanks

    Courses_rev.xlsm

  15. #15
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    Curiously formulas in sheet1 need to "refreshed".
    If you copy one cell (e.g. M2) and paste it in the complete range it updates ....!
    I have no clue why.

  16. #16
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    As for containment (temporary solution) see file attached.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    That didn't work either. As soon as I enabled macros all data on sheet 1 reset to zero.

  18. #18
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    What's up if you copy one cell and paste it in the full range: Copy the formula in all others cells

  19. #19
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    Please check again with file attached
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    I copied a2 to all of the cells. Cell P2 contains =SearchCourses($A2,P$1,Sheet2!$A$1:$E$19)

    I beleive that is correct, isn't it?

  21. #21
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    Same issue with Rev3.

  22. #22
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    Do the copy paste gave some results?
    Yes formula is correct
    I forgot to mention for test files sent, that you have to go in an another sheet that "sheet1" and come back to "sheet1"
    Last edited by PCI; 11-12-2014 at 05:07 PM.

  23. #23
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    Same results.

  24. #24
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    I rebuild completely the file with my Excel, can you check.
    Attached Files Attached Files

  25. #25
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    It works the same way. As soon as enable content, it all goes to 0. I copied and pasted and went to sheet 2 back to sheet 1 and still 0.

  26. #26
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    Do you the chance to test it on another computer (another Excel).

  27. #27
    Registered User
    Join Date
    05-01-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Count Based on Criteria

    Tried it on a different machine. Different version of Excel. Same results. All I have to do to make it populate is go to sheet 2 and back to sheet 1 and it should populate, correct?

  28. #28
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    It should.
    In the last file sent to you (see attached), there is a macro launched when on access to sheet1 and this macro is refreshing one by one each cells formula.
    It is a bit stupid, heavy and not smart but on my PC it works.
    This evening I will see fora macro to do the complete job.
    Attached Files Attached Files

  29. #29
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    See attached a complete remake, a macro is used to update all cells in sheet1.
    This macro is fired when accessing to sheet1 but can be launched manually.
    Attached Files Attached Files

  30. #30
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Count Based on Criteria

    Attached an update of the UDF turned in Volatile mode.
    Of course I did not ask you to check that your Excel is in Automatic calculation mode ..!
    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)

Similar Threads

  1. Count Based on Criteria
    By simplyxl in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-21-2013, 09:32 AM
  2. Count based on criteria.
    By The Phil in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-29-2013, 10:50 PM
  3. A COUNT but based on a second criteria (I think)
    By kirban in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-15-2012, 08:16 AM
  4. Count If based on two criteria
    By randolphoralph in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-03-2008, 10:40 AM
  5. Count or Sum based on more than 1 criteria
    By Andrew C in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-29-2005, 05:50 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