Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default Sort collection string keys

Hi there,

I've got a collection that I want to sort and put into a listbox. The
collection is a series of cell references (delimited with a comma) and each
item has a string key on which I want to sort.

So how can I run through my collection to pull out all the index keys?

Thanks in advance

Best regards

John


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sort collection string keys

to the best of my knowledge, you can't retrieve the index keys.

--
Regards,
Tom Ogilvy

"John" wrote in message
...
Hi there,

I've got a collection that I want to sort and put into a listbox. The
collection is a series of cell references (delimited with a comma) and

each
item has a string key on which I want to sort.

So how can I run through my collection to pull out all the index keys?

Thanks in advance

Best regards

John




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default Sort collection string keys

Thanks Tom. In that case I'd better go back to where the collection gets
built add an duplicate array I suppose.

Thanks again

Best regards

John
"Tom Ogilvy" wrote in message
...
to the best of my knowledge, you can't retrieve the index keys.

--
Regards,
Tom Ogilvy

"John" wrote in message
...
Hi there,

I've got a collection that I want to sort and put into a listbox. The
collection is a series of cell references (delimited with a comma) and

each
item has a string key on which I want to sort.

So how can I run through my collection to pull out all the index keys?

Thanks in advance

Best regards

John






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sort collection string keys

in tools = references, set a reference to the Microsoft Scripting Runtime
library. this will give you access to the dictionary object which does have
a Key property. By setting the reference, you will be able to look at its
properties in the object browser.


here is sample code from MSDN. The use of createObject is an example of
late binding so you don't have to create the reference to use the
dictionary. My recommendation was to do it during development so you would
have access to the object browser.

Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"


Check if it exists


If d.Exists("c") Then
msg = "Specified key exists."
Else
msg = "Specified key doesn't exist."
End If


Use items


a = d.Items ' Get the items.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & "<BR" ' Create return string.
Next


Use keys


a = d.Keys ' Get the keys.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & "<BR" ' Return results.
Next


--
Regards,
Tom Ogilvy

"John" wrote in message
...
Thanks Tom. In that case I'd better go back to where the collection gets
built add an duplicate array I suppose.

Thanks again

Best regards

John
"Tom Ogilvy" wrote in message
...
to the best of my knowledge, you can't retrieve the index keys.

--
Regards,
Tom Ogilvy

"John" wrote in message
...
Hi there,

I've got a collection that I want to sort and put into a listbox. The
collection is a series of cell references (delimited with a comma) and

each
item has a string key on which I want to sort.

So how can I run through my collection to pull out all the index keys?

Thanks in advance

Best regards

John








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default Sort collection string keys

Hi Tom,

This is great. I've not used the dictionary object before, so I'll have a
go.

Thanks very much for the help.

Best regards

John
"Tom Ogilvy" wrote in message
...
in tools = references, set a reference to the Microsoft Scripting Runtime
library. this will give you access to the dictionary object which does
have
a Key property. By setting the reference, you will be able to look at its
properties in the object browser.


here is sample code from MSDN. The use of createObject is an example of
late binding so you don't have to create the reference to use the
dictionary. My recommendation was to do it during development so you
would
have access to the object browser.

Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"


Check if it exists


If d.Exists("c") Then
msg = "Specified key exists."
Else
msg = "Specified key doesn't exist."
End If


Use items


a = d.Items ' Get the items.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & "<BR" ' Create return string.
Next


Use keys


a = d.Keys ' Get the keys.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & "<BR" ' Return results.
Next


--
Regards,
Tom Ogilvy

"John" wrote in message
...
Thanks Tom. In that case I'd better go back to where the collection gets
built add an duplicate array I suppose.

Thanks again

Best regards

John
"Tom Ogilvy" wrote in message
...
to the best of my knowledge, you can't retrieve the index keys.

--
Regards,
Tom Ogilvy

"John" wrote in message
...
Hi there,

I've got a collection that I want to sort and put into a listbox. The
collection is a series of cell references (delimited with a comma) and
each
item has a string key on which I want to sort.

So how can I run through my collection to pull out all the index keys?

Thanks in advance

Best regards

John










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
Many Sort Keys [email protected] New Users to Excel 13 August 3rd 07 01:08 AM
Can't trap error when checking for keys not in Collection BW Excel Programming 6 August 3rd 05 09:15 PM
Collection Object Keys Todd Huttenstine Excel Programming 10 October 29th 04 01:14 PM
sort (on part of) string - originally posted under Tricky Sort Tom Ogilvy Excel Programming 0 August 6th 04 02:42 AM
Sort using 4 keys ChuckM[_2_] Excel Programming 2 February 2nd 04 10:10 PM


All times are GMT +1. The time now is 11:46 PM.

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"