sum values in multiple ranges

C

caroline

in the following code, I am not too sure how to add the cell values in the
defined ranges.
I want each cell in range Addt(j) to equal the sum of cell in range Plus(j)
and this for each N value.

Thanks in advance

Dim Addt(1 To 3) As Range
Set Addt(1) = Range(Range("Region1").Offset( 1,
2), Range("Region1").Offset( 1, 9))
Set Addt(2) = Range(Range("Region1").Offset( 4,
2), Range("Region1").Offset( 4, 9))
Set Addt(3) = Range(Range("Region1").Offset( 8,
2), Range("Region1").Offset( 8, 9))


For j = 1 To UBound(Addt)
For N = 48 to 56

Dim Plus(1 To 3) As Range
Set Plus(1) = Range(Range("Country1").Offset(N +
1, 2), Range("Country1").Offset(N + 1, 9))
Set Plus(2) = Range(Range("Country1").Offset(N +
4, 2), Range("Country1").Offset(N + 4, 9))
Set Plus(3) = Range(Range("Country1").Offset(N +
8, 2), Range("Country1").Offset(N + 8, 9))


How can I write this formula?
Addt(j).value =Addt(j).Value+ Plus(j).Value

next
next
 
J

Joel

See if this works.


Sub test()
Dim Plus() As Variant
Dim Addt() As Variant
AddRows = Array(1, 4, 8)

ReDim Addt(UBound(AddRows))
ReDim Plus(UBound(AddRows))
For J = 1 To UBound(AddRows)
Set Addt(J) = Range(Range("Region1") _
.Offset(AddRows(J), 2), Range("Region1").Offset(AddRows(J), 9))
For N = 48 To 56
Set Plus(J) = Range( _
Range("Country1").Offset(N + AddRows(J), 2), _
Range("Country1").Offset(N + AddRows(J), 9))
Next N
For ColOffset = 0 To (Addt(J).Columns.Count - 1)
Addt(J)(0, ColOffset) = Addt(J)(0, ColOffset) + _
WorksheetFunction.Sum(Plus(J))

Next ColOffset

Next J

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top