Forum Discussion

rodsan724's avatar
rodsan724
Brass Contributor
Aug 25, 2023
Solved

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  
  • HansVogelaar's avatar
    HansVogelaar
    Aug 25, 2023

    rodsan724 

    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

Resources