View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban[_2_] Alan Beban[_2_] is offline
external usenet poster
 
Posts: 783
Default How to read a collection name index value?

Dana DeLouis wrote:
If IsError(V) = True Then



Here's another way to test...

Sub Demo()
Dim d As Scripting.Dictionary
Set d = New Scripting.Dictionary
d.Add "a", "aaa" 'Add key - Items
d.Add "b", "bbb"
d.Add "c", "ccc"

If d.Exists("c") Then
MsgBox "Index is: " & WorksheetFunction.Match("c", d.Keys, 0)
End If
End Sub


The range contains

a b c
d e f
g h i

The function converts the Collection object (Gizmos)into a Dictionary
object with Keys 1 through 9.

Sub abtest4()
Dim arr(), arr1(), Gizmos
Dim rng As range
Set rng = range("G1:I3")
Set Gizmos = New Collection
For i = 0 To rng.Count - 1
Gizmos.Add Item:=rng(i + 1)
Next
Set Gizmos = ConvertCollToDict(Gizmos)
MsgBox Gizmos(2) '<-------Displays b
MsgBox Gizmos.Items(2) 'Displays error message--"Property let
'procedure not defined and property get procedure did not return an
'object" WHAT'S GOING ON WITH THIS?
End Sub
Function ConvertCollToDict(Coll)
Dim q As Scripting.Dictionary, i As Long
Set q = New Scripting.Dictionary
For i = 1 To Coll.Count
q.Add Item:=Coll(i), Key:=(i)
Next
Set ConvertCollToDict = q
MsgBox q(2) '<-----Displays b; i.e., the Item corresponding to Key 2
MsgBox q.Items(2) '<-------Displays c; i.e., the Item corresponding
'to the No.2 Item in the 0-based indexing system
End Function