![]() |
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 |
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 |
All times are GMT +1. The time now is 11:27 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com