![]() |
Excel checkbox date question
There may be an easier way, but I'd go at it like this:
Behind the Click event of each check box, I'd put this code: Private Sub CheckBox1_Click() If CheckBox1.Value Then Call UpdateDateValue(CheckBox1) End Sub Obviously, you'd need to update each Click event to check the appropriate checkbox's value and pass the reference to it. Then add the following code somewhere where that Click event can call it: Private Sub UpdateDateValue(objCheckBox As MSForms.CheckBox) With objCheckBox.Parent.Cells(objCheckBox.TopLeftCell.R ow, objCheckBox.TopLeftCell.Column + 1) If .Value = vbNullString Then .Value = Now End If End With End Sub JimK wrote: Thanks Mike. This worked, but only for the first checkbox (the one in A1). Let's say I have a whole column of checkboxes in column A (A1, A2, A3, etc.). Is there a way that all the checkboxes refer to the same macro, but the macro "knows" to enter a date in the B cell that's next to the checkbox that was checked? "Mike" wrote: assuming your checkbox is in A1 right click on your checkbox and assign the macro If Worksheets("Sheet2").Cells(1, 2).Value = "" Then Worksheets("sheet2").Cells(1, 2).Value = Now() End If format the date cell with the custom format mm/dd/yyyy Mike "JimK" wrote: Hi, I have a checkbox in my worksheet. I'd like the user to click on the checkbox and this action would populate today's date (mm/dd/yyyy) in the cell directly to the right of the check box. I'd like the date to be "hardcoded" and not updated every time the worksheet is opened. I assume I need a macro to do this, but am not sure of the easiest way. Any thoughts would be greatly appreciated. |
All times are GMT +1. The time now is 08:31 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com