+ Reply to Thread
Results 1 to 13 of 13

Code to count and then reset to 0 or blank out.

  1. #1
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Code to count and then reset to 0 or blank out.

    Hey,

    Not sure if this is possible.

    I have a simple count function in D3 - every time there is an entry in A5:A150 it counts up by 1.

    Please Login or Register  to view this content.

    In A5 thru A150 will be a date, is there a way to have D3 reset to 0 and start counting again once the date is not the same as the cell above?

    Is there then a way to capture the number in D3 prior to it reseting to 0 ?
    Last edited by SVTF; 04-12-2010 at 08:12 PM.

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

    Re: VB code to count and capture numbers?

    Posting an example (workbook) would help. If the dates are entered in ascending order, changing occasionally, then maybe this is what you want:

    =COUNTIF(A5:A150, MAX(A5:A150))
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: VB code to count and capture numbers?

    with the above ...

    D3 changes to 1 with something in A5
    but when something added to A6 the count in D3 stays at 1

    Tried changing the date and entered again in A6 and D3 stayed at 1

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

    Re: VB code to count and capture numbers?

    So post an example workbook and explain what you want in context.

  5. #5
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: VB code to count and capture numbers?

    Quote Originally Posted by shg View Post
    Posting an example (workbook) would help

    Here is a sample ... D3 = 5 at the moment.

    So its now April 12th and A10 is about to show 12-Apr ...

    Would like D3 to reset to 0 as soon as 12 -Apr is added to A10

    And if possible, Capture the value of D3 prior to reseting to 0 - and placing that number on another worksheet.
    Attached Files Attached Files
    Last edited by SVTF; 04-11-2010 at 06:28 PM.

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

    Re: VB code to count and capture numbers?

    Why should D3 reset to 0 instead of 1; what's it counting?

    Is it supposed to reset because the date rolled over?

    If you change the formula in D3 to =SUMPRODUCT(--(INT(A5:A150) = INT(MAX(A5:A150)))), it will change to 1 each time the date rolls over, and then count forward from there.

  7. #7
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: VB code to count and capture numbers?

    Cool that works for the date/counting part ...

    When nothing is in A5 to start D3 = 146 ? its counting the blank cells total.

    Would like D3 to be blank or 0 until a date is populated in A5 then D3 changes to 1
    Last edited by SVTF; 04-11-2010 at 07:03 PM.

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

    Re: VB code to count and capture numbers?

    =if(count(a1:a150), sumproduct(--(int(a5:a150) = int(max(a5:a150)))), "")

  9. #9
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: VB code to count and capture numbers?

    Works like a charm - Thanks.

    Another step if possible.

    Is there a way to capture the value of D3 prior to it going to 1 when the date flips over?

    And then put that value on a different sheet in the work book?

  10. #10
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: VB code to count and capture numbers?

    Quote Originally Posted by shg View Post
    =if(count(a1:a150), sumproduct(--(int(a5:a150) = int(max(a5:a150)))), "")
    Thanks again to shg

    This worked but once applying in, need it tweaked a little.
    Last edited by SVTF; 04-12-2010 at 08:10 PM.

  11. #11
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Code to count and then reset to 0 or blank out.

    I need D3 to add up each entry inputed in column A through out the day ...

    Then when I come in the next morning and open the workbook D3 (on each worksheet) would reset to 0 or blank (clear) because it is now a different day.

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

    Re: Code to count and then reset to 0 or blank out.

    Then you could just use

    =sumproduct(--(int(a5:a150) = today()))

    ... to tell you how many entries have today's date.

  13. #13
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Code to count and then reset to 0 or blank out.

    Quote Originally Posted by shg View Post
    Then you could just use

    =sumproduct(--(int(a5:a150) = today()))

    ... to tell you how many entries have today's date.

    Thanks, all you guys must hate us noobies.

    Looks like it will work.

+ 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