Computing Staff
  • 3

Excel Formula & Value In Same Cell

  • 3

I want to add the number in Cell B1 to the number in Cell A1, But have the result in Cell A1
i.e. A1=A1+B1

Share

1 Answer

  1. Hi,

    You can’t do it with standard Excel formulas.

    You can do it with Visual Basic code.

    Right-click the name Tab of your worksheet and select View code.

    In the Visual Basic window that opens enter this:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$1" Then
        'disable events
        Application.EnableEvents = False
        'add B1 value to A1 and save in A1
        Range("A1").Value = Range("A1").Value _
            + Range("B1").Value
    End If
    'reenable events
    Application.EnableEvents = True
    Exit Sub
    'error handler
    ErrHnd:
    Err.Clear
    'reenable events
    Application.EnableEvents = True
    End Sub

    From the Visual Basic menu bar click File- Save
    Click Alt+f11 (the Alt key and function key #11 clicked together) to return to the main Excel window.

    Now when the value in cell B1 is changed, the value in cell A1 will be updated to its original value plus the new value in cell B1.

    This is triggered by Excel’s ‘on change’ event. The code then tests that the changed cell was cell B1 and if it was it does the required addition.

    Regards

    • 0