I have a dynamic range that I want to sum. I'm using lastRow to find the last row of data. The problem is that once I wrap the formula in quotes VBA does not recognize lastrow as a variable. I've tried all sorts of quote combinations - double quotes, triple quotes, apostrophes, etc. None seem to work. The code below does not work.
Sub sum_range()
Dim lastRow As Integer
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("G3").Formula = "=sum(""A2:A"" & lastrow)"
End Sub
It returns =SUM("A2:A" & lastrow) in cell G3.
Any help would be greatly appreciated.
Bookmarks