0

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?

There is a picture of my code at this link: enter image description here

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

4 Comments

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?
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.
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
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.
1

Do you need to use vba? if there are always a set number of numbers to add up, just use an excel formula

 =SUM(A1:A12)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.