Sort problem - part2

G

Guest

I have the following user defined function set up in a workbook and it works
fine but I would like to take it one step further.

Option Explicit
Function SortText(myStr As String) As String

Dim mySplit As Variant
Dim iCtr As Long
Dim jCtr As Long
Dim Temp As Variant

mySplit = Split(myStr, " ")

For iCtr = LBound(mySplit) To UBound(mySplit) - 1
For jCtr = iCtr + 1 To UBound(mySplit)
If mySplit(iCtr) > mySplit(jCtr) Then
Temp = mySplit(iCtr)
mySplit(iCtr) = mySplit(jCtr)
mySplit(jCtr) = Temp
End If
Next jCtr
Next iCtr

SortText = Join(mySplit, " ")

End Function

I would like to have some code that would sort the data in the cells (column
E) without having to add a new column to either place the sorted data or to
hold the sorted data. The data in coulmn E looks like this:

AAI BII TTU QQS AAC NUY GGE BBT

I need those 3 digit (sometimes 4 digit codes) sorted in alpha order. The
number of rows is never the same.
 
D

Dave Peterson

You can use your function with a sub:

Option Explicit
sub testme()
dim mycell as range
with activesheet
for each mycell in .range("E1",.cells(.rows.count,"E").end(xlup))
mycell.value = sorttext(mycell.value)
next mycell
end with
end sub

watch out for typos--I didn't test it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top