Forum Discussion
ReeducBenodet
Jul 21, 2022Copper Contributor
How to add date to cell with a button
Hello, I want to add the date at the end of a line with a button. It's to follow how many time our product are cleanned. I want to have on a line : the product name, a button and all the date of clea...
NikolinoDE
Jul 22, 2022Platinum Contributor
Here is an elegant approach to solving the problem without any button :).
Example in the included file.
Enter the right mouse button in the area A1:B10 and the date appears, pressing it again disappears the date.
VBA Code:
Option Explicit
Private Sub Worksheet_BeforeRightClick(ByVal Target As Excel.Range, Cancel As Boolean)
'Me.Unprotect ("1234")
If Not Intersect(Target, Range("A1:B10")) Is Nothing Then
Target = IIf(Target = "", Date, "")
Cancel = True
End If
'Me.Protect ("1234")
End Sub
Hope I was able to help you with this approach :).
I know I don't know anything (Socrates)