Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
A string of data in a cell | Excel Worksheet Functions | |||
Sorting cells with a string formulas | Excel Worksheet Functions | |||
Extract data in a string | Excel Discussion (Misc queries) | |||
Getting a string of data from a file name | Excel Worksheet Functions | |||
to search for a string and affect data if it finds the string? | Excel Worksheet Functions |