+ Reply to Thread
Results 1 to 11 of 11

How to uncheck checkboxes with Date Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    02-02-2010
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    14

    How to uncheck checkboxes with Date Macro

    I am new to VBA and this Forum. I am trying to create a bit of a tricky Excel Spreadsheet. I currently have a spreadsheet that records our battery recharging information(Crate #, Date last charged, Date for Recharge). This spreadsheet currently has a Macro that when opened sends an email to certain employees as to which crate requires charging. I would like to change it so that instead of manually entering the dates you check a checkbox and the next date automatically comes up. That part is easy. The difficult part is getting the checkbox to uncheck when the date for recharge passes. The code below unchecks the checkboxes but how do I modify it to uncheck when date is less than today?
    Sub ResetAllCheckboxes()
        With ActiveSheet
            For Each chk In .CheckBoxes
                chk.Value = False
            Next
        End With
    End Sub
    Any help would be appreciated!

    Thanks,

    Ash
    Last edited by Ashnette; 02-04-2010 at 01:58 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Need Some help!

    Hello Ash,

    Welcome to the Forum!

    Your post title should convey a brief description of what you need help with. Please do not use general words and phrases like "Help!", "Code doesn't work", "Urgent!", "Should be an easy question", "Is this possible?", etc. Your present title doesn't tell anyone what your question is or what type of problems you are experiencing.
    A better title would be "How to uncheck a CheckBox after a certain date ".

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time.

    How to wrap your Code using the # icon
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    To manually wrap your code, use these Bulletin Board Code Tags
    [code] at the start of the first line,
    [/code] at the end of the last line.

    As a new member, please take the time to read over the Forum Rules .
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    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: How to uncheck checkboxes with Date Macro

    ... how do I modify it to uncheck when date is less than today?
    When what date is less than today? If it's in some cell adjacent to the checkbox, we'd need to see the layout. And if that's true, a Forms checkbox is overkill; you could just use Marlett checkboxes, which are on the same layer as the cells.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    02-02-2010
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: How to uncheck checkboxes with Date Macro

    I included an example of the layout that currently exists, the date in question is the Date For Recharge. Unfortunately, I have never used Marrett checkboxes. If it makes it easier I am all for it.
    Attached Files Attached Files

  5. #5
    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: How to uncheck checkboxes with Date Macro

    There's no checkboxes, Ashnette. Want to back up a step and explain?

  6. #6
    Registered User
    Join Date
    02-02-2010
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: How to uncheck checkboxes with Date Macro

    The update will look similar to this, the last file was an example of the information I am using. If the date that comes up when the checkbox is checked is less than the current date (eg. Today is 2-Feb-2010 and E1 or E2 is 31-Jan-2010), then the checkbox automatically unchecks.
    Attached Files Attached Files

  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: How to uncheck checkboxes with Date Macro

    In the workbook you just posted, delete the checkboxes, and change the font in col A to Marlett. Then insert a formula in A1 and copy down:

    =IF(TODAY() >= E1, "a", "")

  8. #8
    Registered User
    Join Date
    02-02-2010
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: How to uncheck checkboxes with Date Macro

    Unfortunately, that wouldn't work with this worksheet. The original worksheet has a macro that emails certain employees when the date for recharge passes. When the crate is recharged the employee then goes back and enters in the date that he/she finished charging that crate. The goal of using the checkbox was so the employee would check the box when finished charging a crate and a pre-written formula would populate the information after(eg. date charged, date for next recharge). Once the date for recharge passes the checkbox would automatically uncheck. Is there a way to do this with Marlett?

  9. #9
    Registered User
    Join Date
    02-02-2010
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: How to uncheck checkboxes with Date Macro

    While researching the Marlett checkbox I found this code to make the Marlett checkbox a double click instead of manually entering a letter.

    Option Explicit
    
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
            If Target.Count > 1 Then Exit Sub
            If Intersect(Target, Range("myChecks")) Is Nothing Then Exit Sub
            Target.Font.Name = "marlett"
            If Target.Value <> "a" Then
            Target.Value = "a" 
            Cancel = True
            Exit Sub
        End If
        If Target.Value = "a" Then
            Target.ClearContents 
            Cancel = True
            Exit Sub
        End If
    End Sub
    After entering the following code to the Workbook Open section of the file.

    For Each c In Worksheets("Sheet1").Range("H7:H78")
        If c.Value = "Needs Recharge" Then Range("A" & c.Row).Value = "r"
        Next c
    Now with these 2 codes it detects when a crate needs to be recharged and replaces the checkbox letter "a" with an "r"(which comes up as an "X" in Marlett font). When the employee who recharges the crate finishes recharging a crate they then double click the checkbox, which will then change the 'X" back to a check.

  10. #10
    Registered User
    Join Date
    02-02-2010
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: How to uncheck checkboxes with Date Macro

    Thanks to shg and Paul for their help!

  11. #11
    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: How to uncheck checkboxes with Date Macro

    Well done, Ashnette.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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