Ask Your Question

Revision history [back]

click to hide/show revision 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:

  1. Open the Excel template file in Microsoft Excel.

  2. Press the ALT + F11 keys to open the VBA editor.

  3. In the VBA editor, right-click on the sheet name where you want to add the macro and select "View Code".

  4. 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.

  1. Save the macro-enabled Excel template file.

Now, whenever you enter a value in one of the specified cells, the adjacent cell will automatically be populated with the current date.