Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When typing a numeric value in a cell that already has a non-zero numeric value, is there a way to add the value to the existing value of the cell instead of overwriting it? For example, if a cell has a value of 4 and I want to add the value of 2 to the existing value and replace the cell's value with the sum of 6, is there a way to do this directly in Excel? It’s trivial in the example, but the larger the value, the more error-prone the in-my-head procedure becomes. I'm looking for a simple keystroke solution, not a formula that references another cell. Nor do I want to reference a VBA macro as that just adds more keystrokes.

What I have tried:

I've tried the keystroke "+2" as an example.
Posted
Updated 18-Mar-22 12:10pm

1 solution

Trye this:

VBA
Dim wbk as Workbook
Dim wsh As Worksheet

Set wbk = ThisWorkbook 'the workbook which stores the code
Set wsh = wbk.Worksheets("Sheet 1") 'here you store your data
wsh.Range("A1") = wsh.Range("A1") + 2


If you want to change values in a range of cells, you need to loop through that collection of cells.
VBA
Dim i As Integer 
For i = 1 To 10
  wsh.Range("A" & i) = wsh.Range("A" & i) + 2
Next


For further details, please see: Excel Visual Basic for Applications (VBA) reference | Microsoft Docs[^]

Good luck!
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900