Afternoon everyone.
I recently found some great code which allows me to enter a number in cell D2, then when I leave cell D2 the value from D2 is added to C2 and D2 returns to blank, I use this to have a running total in C2.
The issue I have is that I have an ever growing table and want some code that can be applied to every row to do the same thing as above.
Above explains how it works for row 2, however I want the code to basically add the value from column D to the value in column C and then delete the value from column D as I exit the cell and this to work for whichever row I'm on, whether that's row 15 or row 150.
I hope this makes sense and someone can help me.
Below is the code I used for row 2.
Thanks
Mark
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = Range("d2").Address Then
Range("c2") = Range("c2") + Range("d2")
Range("d2").ClearContents
End If
Application.EnableEvents = True
End Sub
I recently found some great code which allows me to enter a number in cell D2, then when I leave cell D2 the value from D2 is added to C2 and D2 returns to blank, I use this to have a running total in C2.
The issue I have is that I have an ever growing table and want some code that can be applied to every row to do the same thing as above.
Above explains how it works for row 2, however I want the code to basically add the value from column D to the value in column C and then delete the value from column D as I exit the cell and this to work for whichever row I'm on, whether that's row 15 or row 150.
I hope this makes sense and someone can help me.
Below is the code I used for row 2.
Thanks
Mark
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = Range("d2").Address Then
Range("c2") = Range("c2") + Range("d2")
Range("d2").ClearContents
End If
Application.EnableEvents = True
End Sub