"Case of Soda (354mL x 24): USD 25.00 Case of Water (0.500L x 24): USD 15.00"
Using the SumNumbers module adds up all numbers but we only want the dollar values.
For example, I have a list of values containing numerical and textual strings, now, I want to sum only the numbers based on the same text, look at the following screenshot. Normally, you can’t sum the values in the list with text string directly, here, I will introduce you some formulas to deal with this task.
Split / Separate text strings into individual text and number columns: Kutools for Excel’s Split Cells feature is a powerful tool, it can help you to split cell values into multiple columns or rows, it can help you to slit alphanumeric strings into separated text and numbers columns, etc… Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now! |
You can use an array formula to sum the numbers based on their corresponding text string within the cell, please do as follows:
1. First you can write down your text strings you want to sum the relative numbers in a column cells.
2. Then type below formula in a blank cell, in this example, I will enter the formula in cell E1: =SUM(IF(ISNUMBER(FIND(D1,$B$2:$B$8)),VALUE(LEFT($B$2:$B$8,FIND(D1,$B$2:$B$8)-1)),0)), and then press Ctrl + Shift + Enter keys together, it will return the total value from the list based on the certain text. See screenshot:
Tip: In the above formula, D1 is the criterion which you want to use, and B2:B8 indicates the cell range you want to sum.
3. Then select the formula cel, and drag the fill handle down to the cells you want to apply this formula to get the result:
If you have the following data which is mixed with text and numbers, and you just want to extract and add up only the numbers in each cell, how could you quickly finish this in Excel?.
To deal with this problem, you can create a User Defined Function, please do as this:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: sum only the numbers in the cell containing numbers and text
Function SumNumbers(rngS As Range, Optional strDelim As String = " ") As Double 'Update 20141210 Dim xNums As Variant, lngNum As Long xNums = Split(rngS, strDelim) For lngNum = LBound(xNums) To UBound(xNums) Step 1 SumNumbers = SumNumbers + Val(xNums(lngNum)) Next lngNum End Function
3. Then save and close this code, go back to the worksheet, and enter this formula =SumNumbers(A1) (A1 indicates the cell you want to sum up the numbers), then drag the fill handle down to the cells you want to fill the formula, and only numbers in each cell are added together, see screenshot:
Sum all individual numbers within a cell If you want to add up all numbers within a cell, Kutools for Excel’s Sum numbers in a cell can help you quickly sum all digits of a number together in a cell. Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now! |
Related articles:
How to sum every n rows down in Excel?
How to sum values based on text criteria in Excel?