Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell

  • Good Morning to All (Especially Dave)!!


    I am back with a new issue from our local commander. (Yes, he is a pain). Anyway, I have included a sample of what we are looking at. I am trying to allow the Command Button when clicked to go through multiple conditions before making a decision. So, when someone clicks on Command Button 3 the code should look to see if CheckBox1 is true, then it should check today's date, and if it is between a range of days, or even months, then it would add the number in TextBox1 with the amount already in cell H18. This event will happen every time someone clicks on the Command Button.


    The end result is to have several sheets (4 total) for each quarter in the fiscal year, and if the dates are within those parameters, the clicking of the command button will update the correct sheet.


    My code doesn't do anything right now. I hope this is the correct way to post a new thread Dave. Please let me know. Thanks for all your help!!


    Go Army!!

  • Re: Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell


    Hello.
    Change :

    Code
    If CheckBox1 = True And Today = DateSerial(2008, 5, 19 - 30) Then


    to

    Code
    If CheckBox1 = True And Date = DateSerial(2008, 5, 19 - 30) Then


    HTH
    Daniel

    Regards.
    Daniel

  • Re: Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell



    Sorry, But that didn't seem to help. The Cell H18 is still not being updated.

  • Re: Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell


    Well, no, because you are comparing todays date and april 19th 2008 which is hard coded in the CommandButton3_Click macro. Please explain the condition when H18 have to be updated. If you changed :

    Code
    If CheckBox1 = True And Date = DateSerial(2008, 5, 19 - 30)


    to :

    Code
    If CheckBox1 = True And Date = DateSerial(2008, 5, 28)


    the cell will be updated.
    Daniel

    Regards.
    Daniel

  • Re: Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell


    Hi there.


    This is the way I would do it. I am using hardcoded date values but you will probably want the user to enter them.


    I have also put in a little error checking incase the textbox is empty.
    i hope this is what your looking for.


  • Re: Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell




    Ok, I see what you are doing. My dates will be permanent with the exception of each year my range will change due to the year will change. The ranges will be each quarter of the fiscal year wihich are like this:


    1st Qtr = 1 Oct 07 - 31 Dec 07
    2nd Qtr = 1 Jan 08 - 31 Mar 08
    3rd Qtr = 1 Apr 08 - 30 Jun 08
    4th Qtr = 1 Jul 08 - 30 Sep 08


    The code I was using does work if you use only one day, (which, daniel c. shows above, which I am not sure where you are getting April since the 5th month is May), but this apparently doesn't work for a range of days. Your code seems to be the code that I may need to use, but would I use the "Else If" command to move to another set of date ranges? I am starting to get confused.

  • Re: Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell


    Quote


    I am not sure where you are getting April since the 5th month is May


    Just to point out that :

    Code
    DateSerial(2008, 5, 19)


    means 5/19/2008
    but

    Code
    DateSerial(2008, 5, 19 - 30)


    means 30 days before that date.
    Daniel

    Regards.
    Daniel

  • Re: Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell


    ok. Firstly, where are the date ranges chosen from? and where is the date to be checked entered from?


    I would use a modular approach. Everytime the command button is pressed, the date to be checked is brought in from where ever it is entered and the range of dates would also be brought in.


    Are these ranges chosen by the user or is it that all the ranges are checked?


    below is the code I would use, but again if all ranges are to be checked there would be a little bit more.


  • Re: Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell



    Oops, sorry Daniel. Not big on what all this code means, but I think I got it working now. I am including the spreadsheet with the code I used. Let me know what you think, and also to double check my codes I used from Ossah. Thank you too Ossah, you were a big help!!

  • Re: Macro: Check CheckBox Is True, Current Date For Day/Month, Then Sum TextBox & Cell


    Yep that seems to work. Again it all depends on where and if the ranges are entered.
    I am not quite sure exactly what you want to do but that code should point you in the right direction.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!