Extract Numeric Value from alfa numeric value

RAMU

Active Member
Joined
Dec 11, 2009
Messages
342
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Mobile
Dear All,
In excel cells there are alfa numeric values like "KEMAJA, KALUA - 680 311, MANDAN BEACH 6453." I wish to extract only the six digit numeric value in another cell by a formula. pls mind , six digit in case of without any space (like 680311) but seven digit with a space (like 680 311) BUT My desired result will be 680311, the formula will never consider the other numeric value like "6453", I mean in case of seven digit that is including the space. I was trying lot but not successful
Need help
Thanks in advance
Regards
RAMU
 
Try. A2=input text
ARRAY formula
Excel Formula:
=SMALL(IF(ISNUMBER(MID(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))-6)),6)+0),MID(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))-6)),6)+0,""),1)
Normal formula, if you have aggregate function.
Excel Formula:
=AGGREGATE(15,6,(MID(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))-6)),6)+0)/ISNUMBER(MID(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))-6)),6)+0),1)

To enter ARRAY formula
Copy and paste the formula in cell
Press F2
Press Ctrl+Shift+Enter together
Excel covers the formula with {}.
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Can you use a UDF? This should work.

VBA Code:
Function Extract6Num(r As String)
r = Replace(r, " ", "")
With CreateObject("vbscript.regexp")
    .Pattern = "\d{6}"
    If .test(r) Then
        Extract6Num = .Execute(r)(0)
    Else
        Extract6Num = "Not Found"
    End If
End With
End Function
Honestly not aware of it, pls help sir
 
Upvote 0
Try. A2=input text
ARRAY formula
Excel Formula:
=SMALL(IF(ISNUMBER(MID(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))-6)),6)+0),MID(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))-6)),6)+0,""),1)
Normal formula, if you have aggregate function.
Excel Formula:
=AGGREGATE(15,6,(MID(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))-6)),6)+0)/ISNUMBER(MID(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))-6)),6)+0),1)

To enter ARRAY formula
Copy and paste the formula in cell
Press F2
Press Ctrl+Shift+Enter together
Excel covers the formula with {}.
both the formulas are not working, error is coming either #NUM! or #VALUE!
 
Upvote 0
Can you use a UDF? This should work.

VBA Code:
Function Extract6Num(r As String)
r = Replace(r, " ", "")
With CreateObject("vbscript.regexp")
    .Pattern = "\d{6}"
    If .test(r) Then
        Extract6Num = .Execute(r)(0)
    Else
        Extract6Num = "Not Found"
    End If
End With
End Function
Sorry, got it, 95% perfect now, let me check all, shall give my feedback
 
Upvote 0
1st formula needs ARRAY entry. Ctrl+Shift+Enter.
2nd formula works in version 2010 and on Words.
Still not working upload a sample file in some website and give link here.
 
Upvote 0

Forum statistics

Threads
1,223,151
Messages
6,170,381
Members
452,322
Latest member
CrimsonCoure

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