Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
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
Sort Problem Abdul Shakeel Excel Discussion (Misc queries) 0 February 7th 10 12:22 PM
sort problem Mike Excel Programming 5 November 29th 05 07:45 PM
Sort Problem Patrick Simonds Excel Programming 3 November 26th 05 11:02 AM
Sort Problem [email protected] Excel Programming 6 May 13th 05 06:33 PM
find largest data (part2) hard work.. Mark[_28_] Excel Programming 1 October 16th 03 12:52 PM


All times are GMT +1. The time now is 04:11 PM.

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

About Us

"It's about Microsoft Excel"