Home > Mobile >  Sum of multiple columns
Sum of multiple columns

Time:07-04

Keep getting error from the below code. I want to create few new columns where each column sum up every single column. Say column K (screen the whole column) gives a total amount in column M. Column L gives a total amount in column N etc.

Dim lastrow As Long
Dim T1 As Long
Dim T2 As Long

lastrow = dws("Summary").Cells(Rows.Count, 2).End(xlUp)
T1 = worksheetfunction.Sum(range ("M2":lastrow))
Range("P2").Value = T1
T2 = worksheetfunction.Sum(range ("N2":lastrow))
Range("Q2").Value = T2

CodePudding user response:

Find the differences

Dim lastrow As Long
Dim T1 As Long
Dim T2 As Long

lastrow = Worksheets("Summary").Cells(Rows.Count, "M").End(xlUp).Row
T1 = Application.WorksheetFunction.Sum(Worksheets("Summary").Range("M2:M" & lastrow))
Worksheets("Sheet2").Range("P2").Value = T1 'Replace "Sheet2" with the name of your sheet
lastrow = Worksheets("Summary").Cells(Rows.Count, "N").End(xlUp).Row
T2 = Application.WorksheetFunction.Sum(Worksheets("Summary").Range("N2:N" & lastrow))
Worksheets("Sheet2").Range("Q2").Value = T2 'Replace "Sheet2" with the name of your sheet
  • Related