Forum Discussion
rodsan724
Aug 25, 2023Brass Contributor
Assign current cell based on value next to it
Give 2 adjacent cells i.e. A1 and A2. How do I make a formula in A1 based off A2. Goal: I'd like a user to be able to enter their initials in A2 and then auto date it in A1
- Aug 25, 2023
Thanks.
Right-click the sheet tab.
Select 'View Code' from the context menu.
Copy the code listed below into the worksheet module.
Switch back to Excel.
Save the workbook as a macro-enabled workbook (*.xlsm).
Make sure that you allow macros when you open the workbook.
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("A2"), Target) Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False If Range("A2").Value = "" Then Range("A1").ClearContents Else Range("A1").Value = Date ' or Now to include the time End If Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub
HansVogelaar
Aug 25, 2023MVP
Do you want A1 to record the date when A2 is first filled, or whenever the value of A2 is edited?
- rodsan724Aug 25, 2023Brass Contributorwhenever A2 is edited.
- HansVogelaarAug 25, 2023MVP
Thanks.
Right-click the sheet tab.
Select 'View Code' from the context menu.
Copy the code listed below into the worksheet module.
Switch back to Excel.
Save the workbook as a macro-enabled workbook (*.xlsm).
Make sure that you allow macros when you open the workbook.
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range("A2"), Target) Is Nothing Then Application.ScreenUpdating = False Application.EnableEvents = False If Range("A2").Value = "" Then Range("A1").ClearContents Else Range("A1").Value = Date ' or Now to include the time End If Application.EnableEvents = True Application.ScreenUpdating = True End If End Sub