Forum Discussion
Eqqsalad
Jul 21, 2023Copper Contributor
Using VBA to add one cell to a second cell and then clear the initial cell
Hello, My goal here is to have one input cell (D9) have its value added to a second cell that will keep a running sum of all numbers input in D9, this total cell will be C7. I'm only a little fam...
HansVogelaar
Jul 21, 2023MVP
You should declare variables before you use them.
You should use variables consistently - you use xpTotal and xpOutput for the same cell.
The keyword Set is used to assign an object variable such as a Range, not to set a number value such as Range("C7").Value.
You could use code like this:
Sub Test2()
Dim xpInput As Range, xpTotal As Range
Set xpInput = Range("D9")
Set xpTotal = Range("C7")
xpTotal.Value = xpTotal.Value + xpInput.Value
xpInput.ClearContents
End Sub