UnCheck checkboxes after 1, 7, 30, 90 and 365 days

marcusmellgren

New Member
Joined
Sep 6, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am really new to Excel and I am really over my skill set. But I really want to have a tasklist, with daily, weekly, monthly, quarterly and yearly tasks.
I also have a checkbox on each row on the different sheets, since I have the dailies on the daily sheet and so on.

Is it possible to program the checkbox to auto UNcheck after x days from I clicked the checkbox as TRUE?

I have the file here: tasklist1.xlsx - Delafil.se if someone wants to have a look.
No virus what-so-ever on that file.

Since Im quite bad at Excel, I find it hard to explain. But in the picture you see what I mean, this is a yearly task, and when I click checkbox in column B I want it to turn into FALSE after 365 days.
What do you think? :)

tasklist1.xlsx
ABCDE
1TRUE-FALSECHECKBOXREFTYPEACTIVITY
2FALSEExempel: Lämna in deklarationen
3FALSE
4FALSE
5FALSE
6FALSE
7FALSE
8FALSE
9FALSE
10FALSE
11FALSE
12FALSE
YEARLY
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:N46Expression=$A2=TRUEtextNO
Cells with Data Validation
CellAllowCriteria
D2:D12List=LISTS!$B$3:$B$10


Marcus
 

Attachments

  • Screenshot 2022-09-06 112002.png
    Screenshot 2022-09-06 112002.png
    38.7 KB · Views: 23

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Welcome to MrExcel forums.

You can do this with VBA code, which means saving the workbook as a macro-enabled workbook (.xlsm file).

Put this code in a standard module:
VBA Code:
Option Explicit

Public Sub Set_OnAction_CheckBoxes_All_Sheets()
  
    Dim ws As Worksheet
    Dim cb As CheckBox
  
    'Set the OnAction property of all checkboxes on all sheets to "CheckBox_Click"
  
    For Each ws In ThisWorkbook.Worksheets
        For Each cb In ws.CheckBoxes
            cb.OnAction = "CheckBox_Click"
        Next
    Next
  
End Sub


Public Sub CheckBox_Click()

    Dim cb As CheckBox
  
    'This macro is called when any Checkbox is clicked.  Application.Caller is name of Checkbox that was clicked
  
    With ActiveSheet
        Set cb = .CheckBoxes(Application.Caller)
        If cb.Value = xlOn Then
            'The checkbox is Ticked - store current date in column O cell
            .Cells(cb.TopLeftCell.Row, "O").Value = Date
        Else
            'The checkbox is Unticked - clear column O cell
            .Cells(cb.TopLeftCell.Row, "O").ClearContents
        End If
    End With
  
End Sub
Put this code in the ThisWorkbook module:
VBA Code:
Option Explicit

Private Sub Workbook_SheetActivate(ByVal Sh As Object)

    Dim ws As Worksheet
    Dim daysOld As Long
    Dim r As Long
  
    Set ws = Sh
    With ws
        'Set the number of days old depending on the current sheet name
        Select Case .Name
            Case "DAILY": daysOld = 1
            Case "WEEKLY": daysOld = 7
            Case "MONTHLY": daysOld = 30
            Case "QUARTERLY": daysOld = 90
            Case "YEARLY": daysOld = 365
        End Select
        For r = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
            If IsDate(.Cells(r, "O").Value) Then
                'A date is in column O cell, is it older than the specified number of days?
                If Date - .Cells(r, "O").Value >= daysOld Then
                    'Yes, so untick the checkbox in the same row by changing its linked cell in column A to False and clear the date in column O
                    .Cells(r, "A").Value = False
                    .Cells(r, "O").ClearContents
                End If
            End If
        Next
    End With
  
End Sub
Next, run the Set_OnAction_CheckBoxes_All_Sheets macro. You only need to run this macro once, or after you add new checkboxes. This macro assigns the CheckBox_Click macro to every checkbox on every sheet.

The idea is that when you click a checkbox the CheckBox_Click macro is run and, if the checkbox is ticked, it stores the date it was ticked in the column O cell, otherwise it clears the cell. And when you activate a sheet, the Workbook_SheetActivate event handler is run which looks at all checkboxes on the sheet and clears those which have a 'tick date' older than the specified number of days. More details are in the code comments.
 
Upvote 0
Welcome to MrExcel forums.

You can do this with VBA code, which means saving the workbook as a macro-enabled workbook (.xlsm file).

Put this code in a standard module:
VBA Code:
Option Explicit

Public Sub Set_OnAction_CheckBoxes_All_Sheets()
 
    Dim ws As Worksheet
    Dim cb As CheckBox
 
    'Set the OnAction property of all checkboxes on all sheets to "CheckBox_Click"
 
    For Each ws In ThisWorkbook.Worksheets
        For Each cb In ws.CheckBoxes
            cb.OnAction = "CheckBox_Click"
        Next
    Next
 
End Sub


Public Sub CheckBox_Click()

    Dim cb As CheckBox
 
    'This macro is called when any Checkbox is clicked.  Application.Caller is name of Checkbox that was clicked
 
    With ActiveSheet
        Set cb = .CheckBoxes(Application.Caller)
        If cb.Value = xlOn Then
            'The checkbox is Ticked - store current date in column O cell
            .Cells(cb.TopLeftCell.Row, "O").Value = Date
        Else
            'The checkbox is Unticked - clear column O cell
            .Cells(cb.TopLeftCell.Row, "O").ClearContents
        End If
    End With
 
End Sub
Put this code in the ThisWorkbook module:
VBA Code:
Option Explicit

Private Sub Workbook_SheetActivate(ByVal Sh As Object)

    Dim ws As Worksheet
    Dim daysOld As Long
    Dim r As Long
 
    Set ws = Sh
    With ws
        'Set the number of days old depending on the current sheet name
        Select Case .Name
            Case "DAILY": daysOld = 1
            Case "WEEKLY": daysOld = 7
            Case "MONTHLY": daysOld = 30
            Case "QUARTERLY": daysOld = 90
            Case "YEARLY": daysOld = 365
        End Select
        For r = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
            If IsDate(.Cells(r, "O").Value) Then
                'A date is in column O cell, is it older than the specified number of days?
                If Date - .Cells(r, "O").Value >= daysOld Then
                    'Yes, so untick the checkbox in the same row by changing its linked cell in column A to False and clear the date in column O
                    .Cells(r, "A").Value = False
                    .Cells(r, "O").ClearContents
                End If
            End If
        Next
    End With
 
End Sub
Next, run the Set_OnAction_CheckBoxes_All_Sheets macro. You only need to run this macro once, or after you add new checkboxes. This macro assigns the CheckBox_Click macro to every checkbox on every sheet.

The idea is that when you click a checkbox the CheckBox_Click macro is run and, if the checkbox is ticked, it stores the date it was ticked in the column O cell, otherwise it clears the cell. And when you activate a sheet, the Workbook_SheetActivate event handler is run which looks at all checkboxes on the sheet and clears those which have a 'tick date' older than the specified number of days. More details are in the code comments.
Wow. I dont know how to thank you.
It is working like a charm <3
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top