Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default sorting data in string

Hi,
How sort data (variable), which add to string.

E.G.:

value of k =
"1-zzz"
"2-zzz"
"3-zzz"
"4-zzz"

Sub sort()
Dim d As String
For k = 1 To 200
d = Cells(k, 1)
d = d & Cells(k, 1)
End Sub

Code above work until data is sorted in column.
and if data is unsorted it doesn't work.
Is there an easy solution?

Regards
Mark
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default sorting data in string

one way:

Public Sub SortK()
Dim d As String
Dim k As Variant
Dim temp As Variant
Dim i As Long
Dim changed As Boolean

k = Range("A1:A200").Value
Do
changed = False
For i = LBound(k, 1) + 1 To UBound(k, 1)
If k(i, 1) < k(i - 1, 1) Then
temp = k(i, 1)
k(i, 1) = k(i - 1, 1)
k(i - 1, 1) = temp
changed = True
End If
Next i
Loop Until Not changed
For i = LBound(k, 1) To UBound(k, 1)
d = d & k(i, 1)
Next i
MsgBox d
End Sub


A more efficient sorting routine would be appropriate if you have
more data.


In article ,
"Mark" wrote:

Hi,
How sort data (variable), which add to string.

E.G.:

value of k =
"1-zzz"
"2-zzz"
"3-zzz"
"4-zzz"

Sub sort()
Dim d As String
For k = 1 To 200
d = Cells(k, 1)
d = d & Cells(k, 1)
End Sub

Code above work until data is sorted in column.
and if data is unsorted it doesn't work.
Is there an easy solution?

Regards
Mark

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
A string of data in a cell Elton Law[_2_] Excel Worksheet Functions 3 June 3rd 10 10:00 AM
Sorting cells with a string formulas Erik Excel Worksheet Functions 1 February 6th 10 11:15 PM
Extract data in a string Tith Excel Discussion (Misc queries) 3 July 25th 08 09:43 PM
Getting a string of data from a file name Stephen King Excel Worksheet Functions 2 July 25th 06 11:57 AM
to search for a string and affect data if it finds the string? Shwaman Excel Worksheet Functions 1 January 11th 06 12:56 AM


All times are GMT +1. The time now is 11:56 AM.

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"