Using XL2002 for Windows, I want to extract and add numbers from cells.
for example, let the following 3 lines each represent 1 cell.
D2K13 V0F4
Y2
H4T10
How can I extract the numbers then add them. For example...
D2K13 V0F4 = 2+13+0+4 = 19
Y2 = 2
H10T4 = 10+4 = 14
Is this possible?
thanks,
Tonso
Pete_UK - 22 Nov 2006 19:37 GMT
You could set up a User Defined Function to replace all characters with
a + in the string, and then pass this to the Evaluate function. If you
are likely to have two or more letters next to each other then the UDF
would have to detect for this.
I'm about to go out now - I'm sure others will be able to expand on
this.
Hope this helps.
Pete
> Using XL2002 for Windows, I want to extract and add numbers from cells.
> for example, let the following 3 lines each represent 1 cell.
[quoted text clipped - 13 lines]
> thanks,
> Tonso
Don Guillett - 22 Nov 2006 20:47 GMT
try this. Change the range to suit>place in a REGULAR module>
then just use as a regular function =gn("orange") or =gn("apple") NOT appleS
Function gn(y)
application.volatile 'may not be necessary
Dim mn As Long
For Each c In Range("c2:c22")
If InStr(c, y) > 0 Then
mn = mn + Val(Left(c, InStr(c, " ")))
End If
Next
gn = mn
End Function

Signature
Don Guillett
SalesAid Software
dguillett1@austin.rr.com
> Using XL2002 for Windows, I want to extract and add numbers from cells.
> for example, let the following 3 lines each represent 1 cell.
[quoted text clipped - 13 lines]
> thanks,
> Tonso
Don Guillett - 23 Nov 2006 12:58 GMT
Obviously for another post

Signature
Don Guillett
SalesAid Software
dguillett1@austin.rr.com
> try this. Change the range to suit>place in a REGULAR module>
> then just use as a regular function =gn("orange") or =gn("apple") NOT
[quoted text clipped - 27 lines]
>> thanks,
>> Tonso
Ron Rosenfeld - 23 Nov 2006 01:38 GMT
>Using XL2002 for Windows, I want to extract and add numbers from cells.
>for example, let the following 3 lines each represent 1 cell.
[quoted text clipped - 13 lines]
>thanks,
>Tonso
One method would be to download and install Longre's free morefunc.xll add-in
from http://xcell05.free.fr
Then use this **array** formula:
=EVAL(MCONCAT(REGEX.MID(A1,"\d+",ROW(
INDIRECT("1:"®EX.COUNT(A1,"\d+")))),"+"))
To enter an **array** formula, after copying or typing the formula into the
formula bar, hold down <ctrl><shift> while hitting <enter>. Excel will place
braces {...} around the formula.
--ron
Dana DeLouis - 23 Nov 2006 03:11 GMT
Here's a Regular Expression example on some test data in A1:A3. Output is
to B1:B3.
Adjust as necessary.
Sub Demo()
Dim RE As Object
Dim Cell As Range
Dim S As String
Const Sp As String = " "
Const P As String = "+"
Set RE = CreateObject("VBScript.RegExp")
RE.Global = True
RE.Pattern = "\D+"
'// Test Data
[A1] = "D2K13 V0F4"
[A2] = " Y2"
[A3] = "H10T4 "
For Each Cell In [A1:A3].Cells
If RE.test(Cell) Then
Cell(1, 2) = Evaluate(Replace(Trim(RE.Replace(Cell, Sp)), Sp, P))
End If
Next Cell
End Sub
Hopefully this will work for your data.

Signature
Dana DeLouis
Windows XP & Office 2003
> Using XL2002 for Windows, I want to extract and add numbers from cells.
> for example, let the following 3 lines each represent 1 cell.
[quoted text clipped - 13 lines]
> thanks,
> Tonso
kounoike - 23 Nov 2006 11:06 GMT
Does this ,though very elementary way of coding, work in your case?
D2K13 V0F4 in A1, and put a formula =myadd(A1) in B1 , then B1 will be 19.
myadd is like this
Function myadd(ByVal s As String) As Variant
Dim t As String, v As String
If s = "" Then myadd = "": Exit Function
Do While (s <> "")
t = Mid(s, 1, 1)
If IsNumeric(t) Then
v = v & t
Else
myadd = myadd + Val(v)
v = ""
End If
s = Mid(s, 2)
Loop
myadd = myadd + Val(v)
End Function
keizi
> Using XL2002 for Windows, I want to extract and add numbers from cells.
> for example, let the following 3 lines each represent 1 cell.
[quoted text clipped - 13 lines]
> thanks,
> Tonso
Lori - 23 Nov 2006 16:00 GMT
=SUM(IF(MMULT(--ISERR(-MID(SUBSTITUTE(A1,"+","|")&"|",(ROW(1:990)-1)/10+
{0,1,1},MOD(ROW(1:990)-1,10)+{2,1,2})),{1;2;4})=5,--MID(A1,(ROW(1:990)-1)/10+
1,MOD(ROW(1:990)-1,10)+1)))
This was published in a prior post - it works on strings up to 99
characters and numbers up to 10 digits by extracting numeric portions
and summing them up.
> Using XL2002 for Windows, I want to extract and add numbers from cells.
> for example, let the following 3 lines each represent 1 cell.
[quoted text clipped - 13 lines]
> thanks,
> Tonso
Lori - 23 Nov 2006 16:04 GMT
Meant to add needs to be array entered (Ctrl+shift+enter) and when you
paste replace 1-0 with 10.
> =SUM(IF(MMULT(--ISERR(-MID(SUBSTITUTE(A1,"+","|")&"|",(ROW(1:990)-1)/10+
> {0,1,1},MOD(ROW(1:990)-1,10)+{2,1,2})),{1;2;4})=5,--MID(A1,(ROW(1:990)-1)/10+
[quoted text clipped - 21 lines]
> > thanks,
> > Tonso
Don - 23 Nov 2006 23:10 GMT
Billy,
Function sumnums(mycell)
c = Len(mycell)
For i = 1 To c
totals = totals + Val(Mid(mycell, i, 1))
Next
sumnums = totals
End Function
Don
> Using XL2002 for Windows, I want to extract and add numbers from cells.
> for example, let the following 3 lines each represent 1 cell.
[quoted text clipped - 13 lines]
> thanks,
> Tonso
Pete_UK - 23 Nov 2006 23:16 GMT
Hi Don,
I've not tried it, but I don't think it would work on this:
D2K13 V0F4
Instead of recognising the 13, your UDF would take the 1 and then the 3
and add them.
Pete
> Billy,
>
[quoted text clipped - 25 lines]
> > thanks,
> > Tonso
Ron Rosenfeld - 23 Nov 2006 23:17 GMT
>Billy,
>
[quoted text clipped - 7 lines]
>
>Don
Your function sums the individual digits. That is NOT what the OP wanted.
--ron
Don - 23 Nov 2006 23:23 GMT
You are right. My Bad.
Don
>>Billy,
>>
[quoted text clipped - 10 lines]
> Your function sums the individual digits. That is NOT what the OP wanted.
> --ron