+ Reply to Thread
Results 1 to 11 of 11

Count rows based on control selection

  1. #1
    Registered User
    Join Date
    06-12-2010
    Location
    Maryland
    MS-Off Ver
    Excel 2007
    Posts
    6

    Lightbulb Count rows based on control selection

    I have a user form that has 2 calender controls, the user selects the beginning and ending dates then clicks the execute button. The execute button is suppose to count the number of rows that match the date range the user selected and return it a label control. Here is my code, which by the way is all wrong and does not work, in it I have commented out ideas that I tried but would only match the dates exactly not the range of dates.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Count rows based on control selection

    Try this

    Please Login or Register  to view this content.

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Countif Using Calendar Controlls as Criteria

    Here is another option

    Please Login or Register  to view this content.
    Last edited by davesexcel; 06-12-2010 at 12:23 PM.

  4. #4
    Registered User
    Join Date
    06-12-2010
    Location
    Maryland
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Count rows based on control selection

    davesexcel,
    I tried the code out and it only returns the number 14 no matter what date I select. I am racking my brain trying to make this work. Any other suggestions?

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Count rows based on control selection

    Did you try Bob's solution,
    You may have to supply a sample workbook

  6. #6
    Registered User
    Join Date
    06-12-2010
    Location
    Maryland
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Count rows based on control selection

    Here is the code as it stands. The issue I am having with it now is that, if I select a starting date other than the first date within the column, which happens to be 6/3/2010 and an ending date of 6/11/2010, then it returns the number 4. If I select 6/3/2010 and 6/11/2010 it return the correct number. I am stumped on this one, any ideas?

    Please Login or Register  to view this content.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Count rows based on control selection

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    06-12-2010
    Location
    Maryland
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Count rows based on control selection

    Let me explain what it is that I am trying to accomplish. My goal is to count the number of cells in column 'D' that fall between the selected dates. Therefore, if I chose a beginning date of 6/3/2010 and an ending date of 6/11/2010 and column 'D' looked like this:

    column D
    6/3/2010
    6/4/2010
    6/4/2010
    6/7/2010
    6/10/2010
    6/11/2010
    6/12/2010

    Then the function would return the number 6.

    In addition, if I chose a beginning and ending date of just 6/4/2010. Then, the function would return the number 4.

    ANy ideas?? I am at a total lose.

  9. #9
    Registered User
    Join Date
    06-12-2010
    Location
    Maryland
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Count rows based on control selection

    I had a thought, could someone assit me in developing a fuction that calculates the number of days in a given range, then searches column 'D' for all those days that meet the criteria. The function will then return the number of cells that match the criteria. I am not sure if this is clear or not, right now it is just an idea.

    Thanks to all

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Count rows based on control selection

    Did you try my suggestion?

    More fully,
    Please Login or Register  to view this content.
    Last edited by shg; 06-13-2010 at 04:32 PM.

  11. #11
    Registered User
    Join Date
    06-12-2010
    Location
    Maryland
    MS-Off Ver
    Excel 2007
    Posts
    6

    Thumbs up Re: Count rows based on control selection

    shg,
    Thank you so very much for you suggestion. I had used it before but withput the CDate function, that was what I needed to make it work. Again, thank you.

    Mekinnik

+ 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