how to run 2 VBA codes on 1 sheet

hh2021

New member
Joined
Jun 19, 2021
Messages
1
Reaction score
0
Points
0
Excel Version(s)
2010
I tried to run 2 simple codes they worked separately. When I ran them together the data was interfered with each other. Please help. Thank you :)

Module1:
Sub calc1()
Range("$D$2").Value = Range("$D$2").Value + Range("$C$2").Value
End Sub

Sub calc2()
Range("$D$10").Value = Range("$D$10").Value + Range("$C$10").Value
End Sub

Sheet1:
Private Sub Worksheet_Calculate()
Call calc1
Call calc2
End Sub

I tried Range("D2:D10").Value = Range("D2:D10").Value + Range("C2:C10").Value not working any idea?
 
Last edited by a moderator:
Try
Code:
Range("D210").Value = Range("D210").Value + WorksheetFunction.Sum(Range("C2:C10"))
 
This works here :

Code:
Sub RunBoth()    Range("$D$2").Value = Range("$D$2").Value + Range("$C$2").Value
    Range("$D$10").Value = Range("$D$10").Value + Range("$C$10").Value
End Sub
 
Code:
Sub Or_Do_You_Mean_So()
Dim i As Long
    For i = 2 To 10
        Cells(i, 4).Value = Cells(i, 4).Value + Cells(i, 3).Value
    Next i
End Sub
 
Back
Top