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...
PeterBartholomew1
Jul 21, 2023Silver Contributor
My only change world be to use defined names rather than direct cell references to reduce the likelihood of the code being broken whenever an end user rearranges the worksheet or inserts rows.
Option Explicit
Sub Test3()
Dim xpInput As Range, xpTotal As Range
Set xpInput = Range("Input")
Set xpTotal = Range("Total")
xpTotal.Value = xpTotal.Value + xpInput.Value
xpInput.ClearContents
End Sub
Then again, I dislike the traditional practice of direct cell referencing in principle, so perhaps I am not the best judge.