PC Review


Reply
Thread Tools Rate Thread

alphabetize within a cell

 
 
hiflyinskiier@gmail.com
Guest
Posts: n/a
 
      14th Feb 2008
if i have a list of letters in a cell, is it possible to alphabetize
them?

example: ADCB --> ABCD
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      14th Feb 2008
Hi,

This will sort A1 into A2

Sub gg()
x = Len(Cells(1, 1))
Cells(2, 1).ClearContents
For i = 1 To x
Cells(i, 2) = Mid(Cells(1, 1), i, 1)
Next i
Cells(1, 2).Resize(x).Sort Key1:=Cells(1, 2), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
For i = 1 To x
Cells(2, 1) = Cells(2, 1) & Cells(i, 2)
Cells(i, 2).ClearContents
Next i
End Sub

Mike

"(E-Mail Removed)" wrote:

> if i have a list of letters in a cell, is it possible to alphabetize
> them?
>
> example: ADCB --> ABCD
>

 
Reply With Quote
 
nickeyre1@gmail.com
Guest
Posts: n/a
 
      14th Feb 2008
On Feb 14, 1:13 pm, Mike H <Mi...@discussions.microsoft.com> wrote:
> Hi,
>
> This will sort A1 into A2
>
> Sub gg()
> x = Len(Cells(1, 1))
> Cells(2, 1).ClearContents
> For i = 1 To x
> Cells(i, 2) = Mid(Cells(1, 1), i, 1)
> Next i
> Cells(1, 2).Resize(x).Sort Key1:=Cells(1, 2), Order1:=xlAscending, _
> Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
> For i = 1 To x
> Cells(2, 1) = Cells(2, 1) & Cells(i, 2)
> Cells(i, 2).ClearContents
> Next i
> End Sub
>
> Mike
>
> "hiflyinski...@gmail.com" wrote:
> > if i have a list of letters in a cell, is it possible to alphabetize
> > them?

>
> > example: ADCB --> ABCD


Is there a way that this can work in any cell, first of all.

second, can it Change ABaD --> AaBD and not ABDa.

third, can it output to the same cell as the input
if not, could it go to an identical position (ex: D7) on a different
worksheet
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      14th Feb 2008
You can use the following as a UDF, like this
=SortLetters(A1)

Option Explicit
'' to sort like a=A use Option Compare Text
' or to sort like ABCabc don't

Option Compare Text

Function SortLetters(v As Variant) As String
Dim bFlag As Boolean
Dim n As Long, i As Long
Dim s As String

n = Len(v)
If n = 0 Then Exit Function

ReDim arrS(0 To Len(v))
For i = 1 To Len(v)
arrS(i) = Mid$(v, i, 1)
Next

Do
bFlag = True
For i = LBound(arrS) To UBound(arrS) - 1
If arrS(i) > arrS(i + 1) Then
bFlag = False
arrS(0) = arrS(i)
arrS(i) = arrS(i + 1)
arrS(i + 1) = arrS(0)
End If
Next i
Loop While Not bFlag

s = ""
For i = 1 To UBound(arrS)
s = s & arrS(i)
Next

SortLetters = s

End Function

Regards,
Peter T

<(E-Mail Removed)> wrote in message
news:b1339197-f017-4179-9e2b-(E-Mail Removed)...
> if i have a list of letters in a cell, is it possible to alphabetize
> them?
>
> example: ADCB --> ABCD



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
alphabetize within a cell hiflyinskiier@gmail.com Microsoft Excel Discussion 13 15th Feb 2008 01:27 PM
Re: alphabetize Don Guillett Microsoft Excel Misc 2 13th Dec 2006 12:36 AM
alphabetize by last name =?Utf-8?B?TGlzYXNtb3Jt?= Microsoft Outlook Contacts 2 27th Feb 2005 11:54 AM
Alphabetize? Old Red One Microsoft Excel Discussion 2 13th Oct 2004 03:33 AM
More on Alphabetize Old Red One Microsoft Excel Discussion 1 7th Oct 2004 06:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:13 AM.