[mso] Re: Sort Excel Spreadsheet

What's so bad about adding a column temporarily to aid in sorting? When I 
Googled this, every solution for similar requests involved adding extra 
columns. You can automate the whole process, like this:
   
  Sub SortAlpha()
'Assuming data is in column A, with heading on row 4.
    Dim LastRow As Long
    LastRow& = Range("A" & Rows.Count).End(xlUp).Row
    Columns(1).Insert
    Range("A5").Activate
    ActiveCell.FormulaR1C1 = "=RIGHT(RC[1],LEN(RC[1])-FirstLetter(RC[1]))"
    Range("A5:A" & LastRow&).FillDown
    Range("A5").CurrentRegion.Select
    Selection.Sort Key1:=Range("A4"), Order1:=xlAscending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
    Columns(1).Delete
End Sub
   
  Function FirstLetter(InTxt As String) As Long
'Checks whether a string contains only letters. Returns
    Dim x As Long, TmpStr As String
    On Error GoTo FLerr1
'If InTxt contains no characters, it's not okay. Return 0.
    If Len(InTxt$) = 0 Then
        FirstLetter = 0
        Exit Function
    End If
    For x& = 1 To Len(InTxt$)
'Look at each character in the input string
        TmpStr$ = LCase(Mid$(InTxt$, x&, 1))
        Select Case TmpStr$
'If it's alphbetic, do nothing - it's okay.
            Case "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", 
"m", _
                 "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
                FirstLetter = x& - 1
                Exit Function
            Case Else
                'do nothing
        End Select
    Next x&
    Exit Function
FLerr1:
    FirstLetter = 0
End Function
  This code must be pasted into a VBA module in the same workbook as the data 
(because of the call to the FirstLetter function from Excel).
   
  Hope this helps,
   
  Hutch
  
George <george@xxxxxxxxxxxxxxxxxx> wrote:
  I have a friend that has a list of chemicals in an Excel spreadsheet. There
are several hundred rows in this list. The chemical names sometimes start
with a number and other times with a letter (3-Bromo-1,1,1-trifluoropropane,
3,5-Difluoronitro benzene, octafluorocyclopentane). Sometimes the first
letter is capitalized and sometimes it is lower case. He wants to sort the
list alphabetically, that is by the first letter in the name whether it has
a number in front of it or not. I have tried using the sort and filter but
both of them sort the numbered names first and then the lettered names next.
How can I get Excel to ignore the numbers w/o having to put them in a
separate column when sorting?








*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, visit the group's homepage and use the dropdown 
menu at the top. This will allow you to unsubscribe your email address or 
change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions. Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles

If you are using Outlook and you see a lot of unnecessary code in your email 
messages, read these instructions that explain why and how to fix it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************


                
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ 
countries) for 2¢/min or less.

*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, visit the group's homepage and use the dropdown 
menu at the top.  This will allow you to unsubscribe your email address or 
change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions.  Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles

If you are using Outlook and you see a lot of unnecessary code in your email 
messages, read these instructions that explain why and how to fix it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************

Other related posts: