Written by Allen Wyatt (last updated October 22, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365
George has a worksheet where the first row, in the range B1:AK1, contains part numbers. Some part numbers begin with X and others begin with Y. He wonders if there is a way to use SUMIF (or some other function) to sum the range B2:AK212 only for those columns in which the first cell in the column (B1:AK1) contains an "X" as the first character in the part number.
One way to accomplish this task is to use the SUMPRODUCT function along with the LEFT function to determine if the part number in the first row starts with an X or not:
=SUMPRODUCT((LEFT(B$1:AK$1,1)="X")*B2:AK212)
The LEFT function returns the leftmost character of the part number and compares it to X. If it is equal, then the result is 1; if not equal then it is 0. This resulting value (1 or 0) is then multiplied by the individual cells in the data range. The result is your desired sum.
If you must use the SUMIF function for some reason, there are two ways you could approach the problem. First, you could add the following into cell AL2:
=SUMIF(B$1:AK$1,"X*",B2:AK2)
This results in a sum of just the cells in row 2 that have a part number beginning with X. Copy the cell downward to cells AL3:AL212, and then sum the column.
The other approach is to add a totals row at the bottom of your data. Thus, you could use the following in cell B213:
=SUM(B2:B212)
Copy this formula to the other cells on the row (C213 through AK213) and then you can use this formula to get your desired sum:
=SUMIF(B1:AK1,"X*",B213:AK213)
In this case, SUMIF is checking the first row (where the part numbers are) and summing the appropriate cells from the totals you just added in row 213.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13471) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365.
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!
Want to figure out how to do a gift exchange for your family or office? There are a variety of ways you can approach the ...
Discover MoreIf you have a long numeric value in a cell, you may have a need to remove the last digit of that value. You can do so ...
Discover MoreExcel provides worksheet functions that make it easy to count things. What if you want to count records that match more ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments