Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Summing Every Fourth Cell in a Row.

Summing Every Fourth Cell in a Row

by Allen Wyatt
(last updated September 29, 2017)

5

Kevin needs to create a formula that sums every fourth cell in a row. He knows he can use a formula such as =A6+E6+I6+M6, etc., but this becomes cumbersome if there are a lot of columns in the worksheet.

There are several ways you can approach this problem. One way is to add some additional information to the worksheet to designate which cells should be included in the sum. For instance, in the example you are interested in summing cells in row 6 of the worksheet. If you can add some indicators in row 5, these could then be used a "triggers" in a formula. Put the number 1, for example, above each cell you want included in the sum (columns A, E, I, M, etc.). Then, you can use a formula such as the following:

=SUMPRODUCT(A5:X5, A6:X6)

The formula basically multiples whatever is in row 5 against row 6, and then sums the results. Since there are only 1s in the columns you want summed, these are all that are included in the final sum.

If you don't want to add an indicator row to your worksheet, then you need to look at different solutions. You could still use the SUMPRODUCT function in a formula such as the following:

=SUMPRODUCT((MOD(COLUMN(6:6),4)=1)*(6:6))

This formula relies on the MOD function to return the remainder of a division. In this case, what is being divided is the column number of a cell by the value 4. This will result in a remainder of either 0, 1, 2, or 3. Every fourth cell in a row will have the same remainder. Thus, column A (also known as column 1) will have a MOD value of 1 (1 divided by 4 is 0, with 1 left over), as will columns E, I, M, etc.

Note that the formula compares whether the MOD value is 1 or not. If it is, then the comparison returns True (1); if it isn't, then it returns False (0). This is then multiplied against the cell in the sixth row. Finally, SUMPRODUCT sums all these multiplications and gives the desired result.

While this formula provides the sum of every fourth cell in the sixth row, it could easily be changed to provide the sum for every third cell, fifth cell, or whatever interval you want. Simply change the 4 in the MOD function to the interval desired.

If you wanted to select a different cell in each "cluster" of four cells to be summed, then all you need to do is change the value being compared in the MOD function. In this example, only the first cell in each cluster of four will have a MOD of 1 (A, E, I, M, etc.). If you instead want to sum every fourth cell starting with, say, cell C, then you would change the comparison value from 1 to 3. Why? Because C is the third cell in the cluster and will have a MOD of 3, as will each fourth cell thereafter (G, K, O, etc.).

The only "gottcha" to this general rule is if you want to sum the fourth cell in each four-cell cluster. For instance, you might want to sum cells D, H, L, P, etc. In this case the comparison value used wouldn't be 4 since there will never be a remainder of 4 when doing a MOD operation that involves dividing by 4. Instead, the comparison value would be 0, as in the following:

=SUMPRODUCT((MOD(COLUMN(6:6),4)=0)*(6:6))

If you prefer to work with array formulas, you can use a slightly shorter variation on the above formula:

=SUM(IF(MOD(COLUMN(6:6),4)=1,6:6))

Note that the formula should be entered by pressing Ctrl+Shift+Enter. It will then appear in the Formula bar with braces ({ }) around the formula. The same modification notes relative to the MOD divisor and comparison value apply here as they did with the SUMPRODUCT function.

Both of these formulaic approaches (SUMPRODUCT and the array formula) sum every fourth cell in the entire row. If you instead want to limit the cells from which the sum is derived to a portion of the row, then simply replace 6:6 (both instances) with the proper range. Thus, if you wanted to only sum every fourth cell in the range of A6:Z6, you would use that range in the formula.

If you do a lot of summing in this manner, and you apply it not only to ranges in a row but ranges in a column, you may want to consider creating a user-defined function to do the summing. The following simple function will do the trick:

Function SumEveryFourth(MyRange As Range)
    Dim x As Integer
    SumEveryFourth = 0
    For x = 1 To MyRange.Cells.Count
        If (x Mod 4) = 1 Then
            SumEveryFourth = SumEveryFourth + MyRange.Cells(x).Value
        End If
    Next x
End Function

The function examines the range passed to it, and then sums every fourth cell starting with the first cell in the range. If you prefer to have it sum every second cell in the range, then change the comparison value in the If statement, as discussed earlier in this tip. (Since the Mod operation is used in this function, and it operates the same as the MOD worksheet function, then the same comparison values come into play for determining which cell in each cluster should be summed.)

The user-defined function will work just fine on either cells in a row or cells in a column. You simply need to make sure that you pass it the range you want, as demonstrated here:

=SumEveryFourth(C3:C57)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9203) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Summing Every Fourth Cell in a Row.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Working with Document Panes

Need to work with two different parts of a document at the same time? The answer is to rely on Word's ability to display ...

Discover More

Decimal Tab Alignment

If you are familiar with decimal tabs in Word, you may wonder if you can set the same sort of alignment in Excel. The short ...

Discover More

Specifying How Changes are Marked

If you want to configure how Word displays changes in your document, you may be at a loss as to where to start. This tip ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Calculating the Median Age of a Group of People

Suppose you have a worksheet that contains a list of ages and then a count of people who correspond with those ages. You may ...

Discover More

Cell and Name References in COUNTIF

The second parameter of the COUNTIF function is used to specify the criteria to be used when determining what should be ...

Discover More

Calculating Monthly Interest Charges

Trying to calculate how much people owe you? If you charge interest or service charges on past-due accounts, there are a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 3 + 8?

2017-10-03 16:53:58

Gary Lundblad

Thank you Daniel! I apologize, but I'm not quite sure how to apply this UDF to a range of data.

Gary


2017-10-03 11:30:21

Gary Lundblad

Thank you Daniel! I apologize, but I'm not quite sure how to apply this UDF to a range of data.

Gary


2017-10-01 22:44:52

Neil

Whilst use of MOD and SUMPRODUCT is clever it is often very hard for another person to follow the logic. I would prefer using the SUMIF statement and be explicit about the criteria that is being used. For example if doing every 4th column then presumably is a quarterly number. In this case to get Q1 totals I would use:

=SUMIF($1:$1,"Q1", 6:6)

Where row 1 has the Q1, Q2, Q3, Q4 indicator etc.

Can also paramaterise the "Q1" if needed.

This is also more robust and less dangerous, for example, if somebody decides to insert annual total columns in it does not require the formula to be rewritten. We should use indicator rows unless there is a very good reason not to - they can be always be hidden if needed.


2017-09-30 10:17:33

Daniel

Gary, you can easily add an input box asking for the factor to use. Actually, the VBA function can be even simplified by adding the Step parameter to the For ... next cycle. Thus one can avoid redundant mod function and if condition:

Function SumEveryNth(MyRange As Range)
Dim x As Integer, N As Integer
SumEveryNth = 0
N = InputBox("Enter nuber:")
For x = 1 To MyRange.Cells.Count Step N
SumEveryNth = SumEveryNth + MyRange.Cells(x).Value
Next x
End Function


2017-09-29 10:59:05

Gary Lundblad

Nice tip! In the VBA code, is there a way to have an input box ask the user which factor he wants to use, i.e. 4 for summing every fourth row, or or 5 for summing every 5th row, etc...? The user would input a "4," for example, and then click "OK." The code would then sum every 4th value in that row.

Thank you!


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.