Forum Discussion
Double click to add date to cell
Hello, I was able to figure out how to make it so you can add the date to cell with the following code
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("E2:E71,F2:F71,G2:G71")) Is Nothing Then
Cancel = True
Target.Formula = Date
End If
End Sub
Now what I am wanting to do is have the text "double click to add date" appear in the cells until the point that a date is added if this is possible.
Thank you.
Hi,
Please try these two methods in the worksheet code module:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("E2:G71")) Is Nothing Then
Cancel = True
Target.Formula = Date
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E2:G71")) Is Nothing Then
If Not IsDate(Target) Then
Target.Value = "double click to add date"
End If
End If
End SubRegards
4 Replies
- Haytham AmairahSilver Contributor
Hi,
Please try these two methods in the worksheet code module:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("E2:G71")) Is Nothing Then
Cancel = True
Target.Formula = Date
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E2:G71")) Is Nothing Then
If Not IsDate(Target) Then
Target.Value = "double click to add date"
End If
End If
End SubRegards
- travisjames.king1Copper Contributor
Thank you for your quick response!
The code you gave me ALMOST works like I need it to. The issue I am running into is that the cell is still blank until I update the cell (by selecting the cell + backspace and pressing enter) This causes the cell to display the message. Will I need to update every cell manually for the text to appear?
(that would be several thousand cells)
- travisjames.king1Copper Contributor
I got it! sorry for the dumb question. Thank you everything works perfectly i just have to drag the cell with the plus sign thing and it updates each cell. Thank you very much again for the help, the sheet is exactly like i want it for now:)