• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 21
  • Last Modified:

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
0
Euro5
Asked:
Euro5
  • 2
2 Solutions
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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