Aug 09 2018 01:31 PM
Hi
If I have a text string in a cell below:
"Path 8.5+Metrocard 10"
And I would like to return the result of the sum of the numbers 8.5+10
"18.5" (see attached image)
How can I do that by using the formula?
The text string might content more than two numbers like "Rent 1000+electric 100+sewage 50"
Is it possible to extract the numbers and sum them in one cell by formulas and functions?
Thanks
Aug 09 2018 06:35 PM - edited Aug 09 2018 07:34 PM
Mr. Chen
copy the function below in a module then call it in the cell you preferred.
example:
A1 = Path 8.5
in cell B1 copy the formula =Digits(A1)*1
B1 will show 8.5
from there you can now do what you want.
** try this in a test workbook -- always make back-up copy of your work.
HTH
Function Digits(ByVal S As String) As String 'courtesy of Rick Rothstein
Dim X As Long
For X = 1 To Len(S)
If Mid(S, X, 1) Like "[!0-9,.]" Then Mid(S, X) = Chr(1)
Next
Digits = Trim(Replace(S, Chr(1), ""))
End Function
Aug 09 2018 07:04 PM - edited Aug 09 2018 08:19 PM
Mr. Chen
I am attaching herewith a sample..
I hope it is what you need.
Aug 09 2018 08:21 PM
prev attached file is a draft.. attached herewith is the correct sample
sorry...
Aug 10 2018 06:59 AM
Thanks!
Is there any possibility to extract the multi digits of a text string and return the sum of these digits in one cell?
Say the text string "Path 8.5+Metrocard 10" is in one cell, and I have thousand cells with similar description, that I can't manually separate the text string into multi string like "Path 8.5" and "Metrocard 10" and use the digit function.
Might need a way to extract the items in the text first? or there is a sophisticated way to do it in one step?
Thanks again
Aug 10 2018 06:59 AM
Aug 10 2018 07:32 AM - edited Aug 10 2018 07:40 AM
Mr. Chen
I don't know if I can do it. But I think it is doable.
unfortunately, I am not an MVP!
but I will try - it is a challenge..
is there always a plus (+) sign between those words?
are the numbers always at the end of each word?
what is the maximum number of words in a cell?
Aug 10 2018 08:38 AM
Aug 10 2018 04:30 PM
Mr. Chen
pls find as attached the sample for you to test.
I hope that it is what you needed.
A rather simple approach (though not that simple at all - I got help from somewhere!)
A much better way is by VBA - this is way out of my league!
but there are many good MVP's here in the forum in case you needed one.
good luck!
Aug 11 2018 03:25 PM
Mr. Chen
attached herewith is the sample again for you to test - this time it had a direct formula - no need for Name Manager.
Hope this is what you needed.
thank you
Aug 11 2018 09:57 PM
Mr. Chen
attached is the best solution (I reckon) for you to test
regards
Aug 14 2018 06:05 AM
Aug 14 2018 03:38 PM
Mr. Chen
Actually, it is outside of my 'powers'..
I sought help somewhere and some helpful people pitched in.
I properly attributed their work in the sub modules.
I am glad it helped you.
Aug 17 2018 01:04 PM
Mar 10 2023 05:58 AM
Mar 13 2023 05:38 AM
Try this:
=LET(arr,WRAPCOLS(TEXTSPLIT(A1,{" ","+"}),2),filtered,FILTER(1*TAKE(arr,-1),TAKE(arr,1)="Path"),SUM(filtered))