Robert Hall
Robert Hall

Reputation: 191

Sum multiple columns in a row

I need to be able to add the numbers up from one table column through to another table column

For i = 1 To PayRatesTable.ListRows.Count
 x = PayRatesTable.ListColumns("Weekday").DataBodyRange(i).Value: 
 PayRatesTable.ListColumns("BLANK").DataBodyRange(i).Value
 MsgBox x
Next i

enter image description here

What i am trying to do is add the numbers up that are betwen the red lines and assign them to x

Upvotes: 1

Views: 172

Answers (1)

Scott Craner
Scott Craner

Reputation: 152660

Create a range of the columns and use Application.Sum no loop needed if you wnat the total of all the data in those columns:

x = Application.Sum(Worksheets("Sheet1").Range(PayRatesTable.ListColumns("Weekday").DataBodyRange, PayRatesTable.ListColumns("BLANK").DataBodyRange))

If you want it row by row then keep the loop and use:

x = Application.Sum(Worksheets("Sheet1").Range(PayRatesTable.ListColumns("Weekday").DataBodyRange(i), PayRatesTable.ListColumns("BLANK").DataBodyRange(i)))

Upvotes: 6

Related Questions