Solved

Sorting numeric text as numbers in Excel

Posted on 2014-10-01
5
184 Views
Last Modified: 2014-10-05
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
Comment
Question by:jeff20850
5 Comments
 
LVL 11

Expert Comment

by:tel2
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 45

Accepted Solution

by:
aikimark earned 500 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

Open in new window


Put it in a module in your VB project.  Then you can invoke the function as you would any other function.
Example:
=text2num(A1)

Open in new window

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

Open in new window

0
 
LVL 25

Expert Comment

by:ProfessorJimJam
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

by:jeff20850
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 45

Expert Comment

by:aikimark
ID: 40362219
post a new question, including a link to this thread and then post a comment in this thread that lets us know the URL of the new related question
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now