• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 511
  • Last Modified:

Excel VBA Loop to add Formula

I am trying to create a simple loop that inserts a formula but I seem to be missing something. I want to:
1) Find the last row with data in it
2) Starting in cell T3 and looping all the way down to the last row I want to insert a formula
3) The formula should be the sum of colums F through S.
What am I missing?

Sub GetTotal()
Dim lstrow As Integer
Dim i As Integer

Application.ScreenUpdating = False
        lstrow = Cells(Rows.Count, 1).End(xlUp).Row
        For i = lstrow
        Range("T3" & lstrow).Formula = "=SUM(RC[-14]:RC[-1])"
        Next i
Application.ScreenUpdating = True

End Sub
 
0
minamina6
Asked:
minamina6
1 Solution
 
NorieCommented:
Try this.
Sub GetTotal()
Dim lstrow As Integer
Dim i As Integer

Application.ScreenUpdating = False

        lstrow = Cells(Rows.Count, 1).End(xlUp).Row

        Range("T3:T" & lstrow).FormulaR1C1 = "=SUM(RC[-14]:RC[-1])"

Application.ScreenUpdating = True

End Sub

Open in new window

0
 
minamina6Author Commented:
Thanks imnorie!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now