I have multiple columns of numbers each 12 rows long. The rows represent sales during each month. I'd like to add up each corresponding month. There are 4 columns of months to be added. How do you do this in Excel VBA?
2 Answers
If you just want the total, you can do this. No need to create separate Range objects:
total = Application.Sum(Range("F21:F32,F35:F46,F49:F60,F63:F74"))
Edit:
If you need to add respective indexes of each range to one another, you can use the Offset() function to make things easier. For example:
For i = 0 To 11
Debug.Print Application.Sum(Range("F21,F35,F49,F63").Offset(i))
Next
4 Comments
user5174899
Thanks but i am not adding up all the data, if you look at the photo i just commented i need to add the numbers in the first row to the numbers in the first row of the 2nd and 3rd column. Then the numbers in the 2nd row need to be added up. Etc. How do i do that?
Bond
I don't understand what you're saying. Your original question (and image) describes four ranges, each 12 rows long that need to be summed. Your new image makes no sense to me.
user5174899
The four ranges do not need to be summed all together. The first row of each range must be summed together. At the very top of the 2nd image i linked, the cell has the number 20 in it. That is Cell F21. F21 or the number 20 must be added to F35, or the number 80 and F49 or the number 100, and then all that must be added to F63 (not shown in the photo). The same must be done for the 2nd row and the 3rd row and 4th row etc. I am not adding together all the numbers in the range. I am only adding the corresponding numbers in the range. Sorry for not being clearer I appreciate your help
Bond
OK, I think I understand what you're asking. I've added an edit to my answer to show you how this can be done with the
Offset() function.