Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sort problem - part2
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sort problem - part2
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. hshayh0rn wrote: 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. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sort Problem | Excel Discussion (Misc queries) | |||
sort problem | Excel Programming | |||
Sort Problem | Excel Programming | |||
Sort Problem | Excel Programming | |||
find largest data (part2) hard work.. | Excel Programming |