# Total columns vba not working

The last few lines of Sub FORMATREPORT() should total the last two columns on Report tab - Ground Rates & MWT Rates.
All I get is an error, but not sure why. Can anyone help?
test.xlsb
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Group Finance ManagerCommented:
Why not format the data as Table and add a Total Row. Most of the code is simply formatting so Format the Table as you want and the formatting will copy down as data is added
Excel TablesExcel Tables

This does not put a formula into the cell, just the result

Range("J" & LastRow) = WorksheetFunction.Sum(Range("J2:J" & LastRow - 1))LastRow = Cells(Cells.Rows.Count, "J").End(xlUp).Row + 1
Range("J" & LastRow) = WorksheetFunction.Sum(Range("J2:J" & LastRow - 1))

This puts a formula in

LastRow = Cells(Cells.Rows.Count, "J").End(xlUp).Row + 1
Range("J" & LastRow).FormulaR1C1= WorksheetFunction.Sum(Range("J2:J" & LastRow - 1))
"=SUM(R[-1582]C:R[-1]C)"
0
Commented:
Hi,

to have a flexible formula pls try

Range("J" & LastRow).Formula = "=SUM(J2:J" & LastRow - 1 & ")"

Regards
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Group Finance ManagerCommented:
Sorry, I pasted the wrong code earlier. to add a formula to the cell it should have been

LastRow = Cells(Cells.Rows.Count, "J").End(xlUp).Row + 1
Range("J" & LastRow).FormulaR1C1 = "=SUM(R[-1582]C:R[-1]C)"
0
Author Commented:
Thanks!!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.