View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_4_] Bob Phillips[_4_] is offline
external usenet poster
 
Posts: 834
Default how to sort a string?

Split the string into an array

ary = Split(sData, ",")

Drop that array onto a worksheet

Set rng = Range("A1").Resize(UBound(ary) - LBound(ary) + 1)
rng = Application.Transpose(ary)

Sort the range

rng.Sort key1:=Range("A1"), order1:=xlAscending, header:=xlNo

Pull that range back into the array

ary = Application.Transpose(rng)

Then join the array back into the string

sData = Join(ary, ",")



"CG Rosen" wrote in message
...
Hi Group

Trying to sort a string looking like:

bv-8,ok-3,bv-5,sk-1,bh-2,ok-9 etc

into:

bh-2,bv-5,bv-8,ok-3,ok-9,sk-1 etc

Grateful for some help.

Brgds

CG Rosen