Summing a row of cells that may also contain text in the same cell

Miff

New Member
Joined
May 4, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Dear All (my first query so please excuse any protocol breaches)

1. I am trying to sum a row of 23 cells that each contain a number and sometimes a number with a letter e.g. 2; 4; 17C; 1; 8F (so it should equal 32).
2. The macro formula below that I found works on an individual cell, but I cannot get it to work across a number of cells (BTW I do not know macros as all).
3. I am not wedded to a macro if there is a simpler way - can anyone assist please with a formula?

Many thanks!

Function SumNumbers(rngS As Range, Optional strDelim As String = " ") As Double
'Updateby Extendoffice
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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
So you want to sum a row of 23 cells, disregarding any text found, just sum the numerical values found in the row?
 
Upvote 0
Yes please - for the avoidance of doubt the letters need to remain in the data set, otherwise I would delete them.
 
Upvote 0
Welcome to the Board!

Try this function:
VBA Code:
Function SumNum(rng As Range) As Double

    Dim cell As Range
    Dim tot As Double
    
    For Each cell In rng
        tot = tot + Val(cell)
    Next cell
    
    SumNum = tot
    
End Function
Then, if you wanted to sum a range, like A10:E10, you would just use the formula:
Excel Formula:
=SumNum(A10:E10)
 
Upvote 0
Solution
Welcome to the Board!

Try this function:
VBA Code:
Function SumNum(rng As Range) As Double

    Dim cell As Range
    Dim tot As Double
   
    For Each cell In rng
        tot = tot + Val(cell)
    Next cell
   
    SumNum = tot
   
End Function
Then, if you wanted to sum a range, like A10:E10, you would just use the formula:
Excel Formula:
=SumNum(A10:E10)
Thank you Joe 4, it works great.

It has prompted a second question to solve. As background the numerical values are sailing race results and the highest (worst) six scores across the 23 races are excluded from the season total. Some of these six worst scores will be say "17F" (as an example) and my formula to recognise the highest scores and deduct them from the total that your macro above creates now doesn't work (as your macro permits me to retain the letters in the cells).

Without pestering you, would you know how to rank the highest to say sixth highest score? Please see snip for representation - far right cell should be an "11" not a "10". I guess I am really asking to have it recognise "17F" as "17" in this example.
 

Attachments

  • Excel Row.JPG
    Excel Row.JPG
    27.2 KB · Views: 7
Upvote 0
It has prompted a second question to solve. As background the numerical values are sailing race results and the highest (worst) six scores across the 23 races are excluded from the season total. Some of these six worst scores will be say "17F" (as an example) and my formula to recognise the highest scores and deduct them from the total that your macro above creates now doesn't work (as your macro permits me to retain the letters in the cells).

Without pestering you, would you know how to rank the highest to say sixth highest score? Please see snip for representation - far right cell should be an "11" not a "10". I guess I am really asking to have it recognise "17F" as "17" in this example.
That is an entirely new, different question, and should be posted in a new thread.
 
Upvote 0
I am not wedded to a macro if there is a simpler way - can anyone assist please with a formula?

For the original question, if the cells with text only ever include a single letter then you could use a standard worksheet formula like this.
The first formula assumes no blank cells in the range.
If there could be blanks then the second formula may be of use to you.

21 05 06.xlsm
ABCDEF
12417C18F32
2217C18F28
SUMPRODUCT
Cell Formulas
RangeFormula
F1F1=SUMPRODUCT(--LEFT(A1:E1,LEN(A1:E1)-ISERROR(RIGHT(A1:E1,1)+0)))
F2F2=SUMPRODUCT(--LEFT(0&A2:E2,LEN(0&A2:E2)-ISERROR(RIGHT(0&A2:E2,1)+0)))
 
Upvote 0
Dear All

I have a small format -

cc 5
sd 30
sd 20
sdc 10
cc 10
sd 40

I want to sum the names individually : sd, cc, sdc etc like -

sd90
sdc10
cc15
Total:​
115

Please advise, Thanks,

Sandeep
 
Upvote 0
Like this?

22 03 13.xlsm
ABCD
1cc 5sd90
2sd 30sdc10
3sd 20cc15
4sdc 10
5cc 10
6sd 40
Sum with text
Cell Formulas
RangeFormula
D1:D3D1=SUMPRODUCT(--MID(A$1:A$6,FIND(" ",A$1:A$6),20),--(LEFT(A$1:A$6,FIND(" ",A$1:A$6)-1)=C1))
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,109
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top