Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old February 1st 21, 08:20 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Oct 2018
Posts: 25
Default Insert into presorted list

I have these variables:

sSorted = "ant, dog, giraffe, rhino, wolf, zebra"
sMixed = "pig, snake, coyote"

I want to build this newly sorted list:

aSort2 = "ant, coyote, dog, giraffe, pig, rhino, snake, wolf, zebra"

What would be some quick ways to merge both lists in a sorted manner?

Thanks!

  #2   Report Post  
Old February 1st 21, 09:48 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2011
Posts: 3,866
Default Insert into presorted list

Hi,

Am Mon, 1 Feb 2021 12:20:14 -0800 (PST) schrieb Tatsujin:

I have these variables:

sSorted = "ant, dog, giraffe, rhino, wolf, zebra"
sMixed = "pig, snake, coyote"

I want to build this newly sorted list:

aSort2 = "ant, coyote, dog, giraffe, pig, rhino, snake, wolf, zebra"


try:

Sub SortedList()
Dim sSorted As String, sMixed As String, myStr As String, varbuffer As String
Dim vardata As Variant
Dim i As Integer, k As Integer, lngUp As Integer, lngLow As Integer

sSorted = "ant, dog, giraffe, rhino, wolf, zebra"
sMixed = "pig, snake, coyote"
myStr = sSorted & ", " & sMixed
vardata = Split(myStr, ", ")

lngUp = UBound(vardata)
lngLow = LBound(vardata)

For i = lngLow To lngUp - 1
For k = lngUp To i + 1 Step -1
If vardata(i) vardata(k) Then
varbuffer = vardata(k)
vardata(k) = vardata(i)
vardata(i) = varbuffer
End If
Next
Next
myStr = Join(vardata, ", ")
Range("A1") = myStr
End Sub


Regards
Claus B.
--
Windows10
Microsoft 365 for business
  #3   Report Post  
Old February 2nd 21, 08:22 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Oct 2018
Posts: 25
Default Insert into presorted list

On Monday, February 1, 2021 at 2:48:26 PM UTC-7, Claus Busch wrote:

Sub SortedList()
Dim sSorted As String, sMixed As String, myStr As String, varbuffer As String
Dim vardata As Variant
Dim i As Integer, k As Integer, lngUp As Integer, lngLow As Integer
sSorted = "ant, dog, giraffe, rhino, wolf, zebra"
sMixed = "pig, snake, coyote"
myStr = sSorted & ", " & sMixed
vardata = Split(myStr, ", ")

lngUp = UBound(vardata)
lngLow = LBound(vardata)

For i = lngLow To lngUp - 1
For k = lngUp To i + 1 Step -1
If vardata(i) vardata(k) Then
varbuffer = vardata(k)
vardata(k) = vardata(i)
vardata(i) = varbuffer
End If
Next
Next
myStr = Join(vardata, ", ")
Range("A1") = myStr
End Sub


Good stuff yet again! Thank you very much.


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
insert row at end of list Joel Excel Programming 0 February 2nd 09 11:26 AM
Drop down List - insert row? DianneB Excel Discussion (Misc queries) 3 November 4th 08 06:07 PM
insert rows in list Evelyn Excel Worksheet Functions 4 October 22nd 08 08:12 PM
Insert Name Paste List Philip J Smith Excel Discussion (Misc queries) 3 January 24th 08 06:29 PM
Insert Row between items in list ... WCM Excel Discussion (Misc queries) 2 May 25th 07 10:42 PM


All times are GMT +1. The time now is 10:22 PM.

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

About Us

"It's about Microsoft Excel"

 

Copyright © 2017