Cell addition


Posted by David Jones on January 14, 2002 6:15 AM

Hello all. I imagine this is a very simple process, but I have had no luck searching the Excel help features.

Can anyone please tell me if it is possible to highlight a cell with an existing value, enter a new value, and have the cell add the two values together and display the new value? i.e. I have a cell with 3 in it. I highlight the cell, type the number 4, hit TAB to move to the next cell and have 7 now appear in the adjusted cell instead of 3.

Forgive my Excel "greenness." Any help would be appreciated.

DJ



Posted by Mopsa on January 14, 2002 6:34 AM


This can only be done with VBA.
See if this does what you want. Put the following code in the Sheet code module. The code restricts the operation to cell A1. Adjust it as required.

Dim x As Double
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then x = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$A$1" Then Target.Value = x + Target.Value
Application.EnableEvents = True
End Sub