Reputation: 1793
I got a problem with sum of rows formula in vba.
I am using the below code. When I check the value in Range("H3").Formula
its giving me the correct value =SUM(C5:G5)
But the problem is its not reflecting in the excel cell.
Range("H3").Formula = "=SUM(" & Range(Cells(5, 3), Cells(5, 7)).Address(False, False) & ")"
Upvotes: 0
Views: 1003
Reputation: 149287
You need to fully qualify the cells (notice the dots). Try this
'~~> Replace this with the relevant sheet
With Sheets("Sheet1")
.Range("H3").Formula = "=SUM(" & _
.Range(.Cells(5, 3), .Cells(5, 7)).Address(False, False) & _
")"
End With
Upvotes: 1