Extract Numeric characters

maheshmaxi

Active Member
Joined
Dec 16, 2008
Messages
252
Hi,

I have a column contains Postal Adress in more than 5000 rows. Column contains Door Number, Area, City and Zip code. I need to separate "Zip code" alone in next coulmn. Zip code (of India) will be in six digits like "600083" also some cases contain space in middle of zip code like "600 083" (after 3 digits). Is there any way to do this without doing cut & paste? Pls help me...:banghead:
 

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.
Will there always be a space after the 6th numeral, as in "600083 " or "600 083 "?

If so, this might work
=MID(A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&"1234567890")),7)

unless there are other numerals in the cell.
 
Last edited:
Upvote 0
Thanks for your reply:)

Yes, may be but in rare cases, since the data received from multiple sources in different formats.
 
Upvote 0
may be this

Excel Workbook
ABC
39A 600036600036600036
Sheet2
#VALUE!
Entered with Ctrl+Shift+Enter



from here

http://www.mrexcel.com/forum/showthread.php?t=399606

Thanks sanrv1f,

But second formula is working fine. But the result includes Door No. also. I just need the zip code alone. It will be in 6 or 7 digits of three types (with or without space) like "600086", "600 086" & "600 086 ".
 
Upvote 0
may be this, (this won't work, if the door no or any number other than PINCODE starts with 600)
Excel Workbook
IJ
3245 A 600 036600036
3345 A 600036600036
Sheet2
Cell Formulas
RangeFormula
J32=SUBSTITUTE(MID(I32,SEARCH(600,I32),7)," ","")
J33=SUBSTITUTE(MID(I33,SEARCH(600,I33),7)," ","")


the UDF can be used to extract all the number in a string (not a part of it),
 
Upvote 0
=ZipCode(A1)
Code:
Function ZipCode(ByVal txt As String) As String
With CreateObject("VBScript.RegExp")
    .Pattern = "\b(\d{3}\s?\d{3})\b"
    If .test(txt) Then
        ZipCode = .execute(txt)(0).submatches(0)
    End If
End With
End Function
 
Upvote 0
Thanks sanrv1f,

But second formula is working fine. But the result includes Door No. also. I just need the zip code alone. It will be in 6 or 7 digits of three types (with or without space) like "600086", "600 086" & "600 086 ".

I am probably not thinking great, but would this work?<font face=Courier New><SPAN style="color:#00007F">Option</SPAN><SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> callit()<br><SPAN style="color:#00007F">Dim</SPAN> rCell<SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">For</SPAN><SPAN style="color:#00007F">Each</SPAN> rCell<SPAN style="color:#00007F">In</SPAN> Selection<br>        rCell.Offset(, 1).Value = StripZip(rCell)<br>    <SPAN style="color:#00007F">Next</SPAN><br><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Function</SPAN> StripZip(rng<SPAN style="color:#00007F">As</SPAN> Range)<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">String</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> a<br>    <br>    a = Application.WorksheetFunction.Trim(rng.Value)<br>    <br>    <SPAN style="color:#00007F">If</SPAN> InStrRev(a, Chr(32), -1, vbTextCompare) >= Len(a) - 5<SPAN style="color:#00007F">Then</SPAN><br>        <br>        StripZip = Mid(a, InStrRev(a, Chr(32), Len(a) - 4, vbTextCompare) + 1, 8)<br>    <SPAN style="color:#00007F">Else</SPAN><br>        StripZip = Mid(a, InStrRev(a, Chr(32), -1, vbTextCompare) + 1, 8)<br>    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Function</SPAN><br></FONT>

Book1
ABCD
14320W.CabCompanmy907803907803
21321321NYooHoo903093903093
398349WRollingHills90430909043090
4Highwater9080980980
Sheet1


It would not catch trailing four digits after a space.

Mark
 
Upvote 0
=ZipCode(A1)
Code:
Function ZipCode(ByVal txt As String) As String
With CreateObject("VBScript.RegExp")
    .Pattern = "\b(\d{3}\s?\d{3})\b"
    If .test(txt) Then
        ZipCode = .execute(txt)(0).submatches(0)
    End If
End With
End Function


Thanks Seiya, Its working great.:)
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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