1 | initial version |
To add a macro to an Excel template created in VBA Access to automatically populate the date whenever a cell contains values, follow these steps:
Open the Excel template file in Microsoft Excel.
Press the ALT + F11 keys to open the VBA editor.
In the VBA editor, right-click on the sheet name where you want to add the macro and select "View Code".
In the code window, enter the following code:
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("A1:A100")) Is Nothing _ And Target.Value <> "" _ And Target.Offset(0, 1).Value = "" Then Target.Offset(0, 1).Value = Date End If End Sub
Note: Replace "A1:A100" with the range of cells where you want the macro to apply.
Now, whenever you enter a value in one of the specified cells, the adjacent cell will automatically be populated with the current date.