Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default alphabetize within a cell

if i have a list of letters in a cell, is it possible to alphabetize
them?

example: ADCB -- ABCD
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default alphabetize within a cell

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

" wrote:

if i have a list of letters in a cell, is it possible to alphabetize
them?

example: ADCB -- ABCD

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default alphabetize within a cell

On Feb 14, 1:13 pm, Mike H 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

" 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default alphabetize within a cell

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

wrote in message
...
if i have a list of letters in a cell, is it possible to alphabetize
them?

example: ADCB -- ABCD



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
alphabetize Ahsen New Users to Excel 1 February 1st 07 04:13 AM
alphabetize EC Excel Discussion (Misc queries) 4 December 13th 06 12:36 AM
alphabetize - automatically mandyjo830 Excel Worksheet Functions 2 November 14th 06 09:30 PM
Alphabetize? lisaz530 Excel Discussion (Misc queries) 1 August 16th 06 01:12 AM
Alphabetize a sort. Tomk Excel Discussion (Misc queries) 8 May 7th 06 06:00 AM


All times are GMT +1. The time now is 06:18 AM.

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

About Us

"It's about Microsoft Excel"