Assuming between 1 & 9 digits at the start of the data (adjust as required) you can use this formula
=LOOKUP(10^10,LEFT(A1,{1,2,3,4,5,6,7,8,9})+0)
Вопрос
I have entries in cells like this:
75864543&m
2211842
1523674&mr
3452435tr
The cells have varying numbers of numeric values, and some have characters/letters at the end. I want to trim everything off except numeric values, but am stuck due to the varying length of number values.
Does anyone have a workaround?
Решение
Assuming between 1 & 9 digits at the start of the data (adjust as required) you can use this formula
=LOOKUP(10^10,LEFT(A1,{1,2,3,4,5,6,7,8,9})+0)
Другие советы
Try the following User Defined Function:
Public Function ReturnNumerals(rng As Range) As String
Dim sStr As String, i As Long, sStr1 As String
Dim sChar As String
sStr = rng.Value
For i = 1 To Len(sStr)
sChar = Mid(sStr, i, 1)
If sChar Like "[0-9]" Then
sStr1 = sStr1 & sChar
End If
Next
ReturnNumerals = sStr1
End Function
EDIT #1:
If you are "macrophobic" or VBA is ruled out for other reasons, Then try this array formula:
=MID(SUMPRODUCT(--MID("01"&A1,SMALL((ROW($1:$300)-1)*ISNUMBER(-MID("01"&A1,ROW($1:$300),1)),ROW($1:$300))+1,1),10^(300-ROW($1:$300))),2,300)
Array formulas must be entered with CNTRL-SHFT-ENTER rather than just the ENTER key!
For example, if A1 contains:
a123wer98bg5
the ugly array formula will return:
123985