Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Sorting numeric text as numbers in Excel

Posted on 2014-10-01
Medium Priority
197 Views
I have a column of real estate case identifiers in a spreadsheet.  The format of the case id's can differ, but they all mix numeric and alpha characters.  A sample column of id's might look like the following:

12-3
12-4
12-34
12-5
12-45
2013CA235
12-672CO

As a first step, I want to eliminate the alpha characters from each id and then sort the list as numbers.  Any ideas?
0
Question by:jeff20850
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 12

Expert Comment

ID: 40356084
Hi Jeff,

When you say "...eliminate the alpha characters...", do you mean "...eliminate the non-numeric characters..."?  Alpha (alphabetics) are just letters (a-z & A-Z), but I see you have '-'s also.

Also, what version of Excel are you using?

tel7
0

LVL 46

Accepted Solution

aikimark earned 2000 total points
ID: 40356166
This function will do a text to number conversion.
``````Public Function Text2Num(ByVal parmText As String)
Static oRE As Object
Static strTemp As String
If oRE Is Nothing Then
Set oRE = CreateObject("vbscript.regexp")
oRE.Global = True
oRE.Pattern = "\D"
End If
strTemp = parmText
If oRE.test(strTemp) Then
strTemp = oRE.Replace(strTemp, "")
End If
Text2Num = strTemp
End Function
``````

Put it in a module in your VB project.  Then you can invoke the function as you would any other function.
Example:
``````=text2num(A1)
``````
Your sample data is in column A and the function result in column B.
``````12-3        	123
12-4        	124
12-34      	1234
12-5        	125
12-45      	1245
2013CA235	2013235
12-672CO	12672
``````
0

LVL 27

Expert Comment

ID: 40360523
do it with no UDF just with array formulas

extract numeric from alphanumerics and then sort with formula.

see attached file. very useful array formulas
C--Users-Jamil-Desktop-Book1.xlsx
0

Author Closing Comment

ID: 40362215
Answered my question exactly. This function is really the first step in my overall question, so I'll correcpond with the replier to ask some follow-up questions.
0

LVL 46

Expert Comment

ID: 40362219
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describesâ€¦
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
###### Suggested Courses
Course of the Month9 days, left to enroll