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
Euro5Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Roy CoxGroup 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))

Open in new window


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)"

Open in new window

0
Rgonzo1971Commented:
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

Your issues matter to us.

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

Start your 7-day free trial
Roy CoxGroup 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)"

Open in new window

0
Euro5Author 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.