I need a way to use SUM in a loop across columns

12 Views Asked by At

I have got a number of columns for which I want to do the same, namely summarize, average and round.

This works, but I would like to include the 7 summarize statements into the loop below. I don't know (and cant' find out) how you describe a range using indexes:

' Summarize
Cells(x + 2, 23) = Application.WorksheetFunction.Sum(Range("W2:W" & x + 1))
Cells(x + 2, 24) = Application.WorksheetFunction.Sum(Range("X2:X" & x + 1))
Cells(x + 2, 25) = Application.WorksheetFunction.Sum(Range("Y2:Y" & x + 1))
Cells(x + 2, 26) = Application.WorksheetFunction.Sum(Range("Z2:Z" & x + 1))
Cells(x + 2, 27) = Application.WorksheetFunction.Sum(Range("AA2:AA" & x + 1))
Cells(x + 2, 28) = Application.WorksheetFunction.Sum(Range("AB2:AB" & x + 1))
Cells(x + 2, 29) = Application.WorksheetFunction.Sum(Range("AC2:AC" & x + 1))
' Average and round
For y = 23 To 29
' Average
    Cells(x + 3, y) = Cells(x + 2, y) / x
' Rounded
    Cells(x + 4, y) = Round((Cells(x + 3, y)), 0)
Next

I have tried all sort of structures, and I hopes to solve the problem using fewer statements.

0

There are 0 best solutions below