Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Sorting Street Numbers

I'm using Excel 2007. How would I sort the following:

1111th
131st
1st
223rd
2nd
3rd
65th

to get:

1st
2nd
3rd
65th
131st
223rd
1111th


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sorting Street Numbers

One play to try on a copy of your data sheet
(Tested fine here in xl2003)

Assume data as posted in col A
a. Insert a new col B (if reqd). Copy n paste col A into col B.
b. Install* & Run** Gord's sub below on col B to remove all alphas
c. Select the entire table, do a Data Sort Sort by col B, Ascending

*To Install:
Press Alt+F11 to go to VBE. Click InsertModule. Copy n paste Gord's sub
below into the code window (whitespace on the right). Press Alt+Q to get back
to Excel.

**To Run:
Select col B (or select the data range in col B). Press Alt+F8 to bring up
the macro dialog. Select "RemoveAlphas" Run (or just double-click on
"RemoveAlphas")

'-------
Sub RemoveAlphas()
' Gord Dibben
'' Remove alpha characters from a string
Dim intI As Integer
Dim rngR As Range, rngRR As Range
Dim strNotNum As String, strTemp As String
Set rngRR = Selection.SpecialCells(xlCellTypeConstants, _
xlTextValues)
For Each rngR In rngRR
strTemp = ""
For intI = 1 To Len(rngR.Value)
If Mid(rngR.Value, intI, 1) Like "[0-9,.]" Then
strNotNum = Mid(rngR.Value, intI, 1)
Else: strNotNum = ""
End If
strTemp = strTemp & strNotNum
Next intI
rngR.Value = strTemp
Next rngR
End Sub
'-------

--
Max
Singapore
http://savefile.com/projects/236895
Downloads:20,500 Files:363 Subscribers:64
xdemechanik
---
"BASR52" wrote:
I'm using Excel 2007. How would I sort the following:

1111th
131st
1st
223rd
2nd
3rd
65th

to get:

1st
2nd
3rd
65th
131st
223rd
1111th


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sorting Street Numbers

Here's an alternative sub by Harlan which also removes the alphas:

Sub DeleteAlphas()
' Harlan
Dim rng As Range, c As Range, re As Object

Set rng = Selection.SpecialCells( _
Type:=xlCellTypeConstants, _
Value:=xlTextValues _
)

Set re = CreateObject("vbscript.regexp")
re.Pattern = "[^0-9.]+" 'or use an InputBox to set
re.Global = True

For Each c In rng
c.Formula = re.Replace(c.Formula, "")
Next c
End Sub

--
Max
Singapore
http://savefile.com/projects/236895
Downloads:20,500 Files:363 Subscribers:64
xdemechanik
---
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Sorting Street Numbers

This is an excellent idea! I never thought about having an additional column
minus the alpha characters to sort by. Thanks!

"Max" wrote:

One play to try on a copy of your data sheet
(Tested fine here in xl2003)

Assume data as posted in col A
a. Insert a new col B (if reqd). Copy n paste col A into col B.
b. Install* & Run** Gord's sub below on col B to remove all alphas
c. Select the entire table, do a Data Sort Sort by col B, Ascending

*To Install:
Press Alt+F11 to go to VBE. Click InsertModule. Copy n paste Gord's sub
below into the code window (whitespace on the right). Press Alt+Q to get back
to Excel.

**To Run:
Select col B (or select the data range in col B). Press Alt+F8 to bring up
the macro dialog. Select "RemoveAlphas" Run (or just double-click on
"RemoveAlphas")

'-------
Sub RemoveAlphas()
' Gord Dibben
'' Remove alpha characters from a string
Dim intI As Integer
Dim rngR As Range, rngRR As Range
Dim strNotNum As String, strTemp As String
Set rngRR = Selection.SpecialCells(xlCellTypeConstants, _
xlTextValues)
For Each rngR In rngRR
strTemp = ""
For intI = 1 To Len(rngR.Value)
If Mid(rngR.Value, intI, 1) Like "[0-9,.]" Then
strNotNum = Mid(rngR.Value, intI, 1)
Else: strNotNum = ""
End If
strTemp = strTemp & strNotNum
Next intI
rngR.Value = strTemp
Next rngR
End Sub
'-------

--
Max
Singapore
http://savefile.com/projects/236895
Downloads:20,500 Files:363 Subscribers:64
xdemechanik
---
"BASR52" wrote:
I'm using Excel 2007. How would I sort the following:

1111th
131st
1st
223rd
2nd
3rd
65th

to get:

1st
2nd
3rd
65th
131st
223rd
1111th


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sorting Street Numbers

Welcome, glad it got you going.
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:20,500 Files:362 Subscribers:64
xdemechanik
---
"BASR52" wrote in message
...
This is an excellent idea! I never thought about having an additional
column
minus the alpha characters to sort by. Thanks!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Separate address numbers from street name Walt Moeller Excel Worksheet Functions 5 May 7th 23 07:42 PM
How do you remove the numbers from a street address in EXCELL? BNA Bill Excel Worksheet Functions 3 July 20th 06 10:36 PM
Sorting street addresses Marta Excel Discussion (Misc queries) 5 July 18th 06 01:33 AM
how do I convert cell 'Street,#' to '# Street' these are addresse Closing hyperlinked wookbooks upon exit Excel Worksheet Functions 3 April 30th 06 11:23 AM
How do I sort a column of street number/street name by the stree. JHoleman1 Excel Worksheet Functions 3 January 8th 05 12:18 AM


All times are GMT +1. The time now is 09:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"