Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi All,
This may seem really easy but it has elluded me for a while. I'm trying to figure out the correct syntax to capture an error when a collection key is not part of the collections contents, ie. if not colActiveCollection("NoSuchKey") IsNothing then .... end if The problem is that "NoSuchKey" is not in the collection. So it returns an Object Error and not Nothing. So how can I check the container without having to iterate over the entire collection looking for a match? I'm sure that the answer is below simple, so sorry for having to post such a simple question. Paul. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Paul,
I assume based on your description that you're holding some kind of object in your collection. In that case, here's one way to solve the problem: Dim objThing as Object Set objThing = Nothing On Error Resume Next Set objThing = colActiveCollection("NoSuchKey") On Error Goto 0 If objThing Is Nothing Then ''' There's no NoSuchKey in the collection. Else ''' The item was located. End If -- Rob Bovey, MCSE, MCSD, Excel MVP Application Professionals http://www.appspro.com/ * Please post all replies to this newsgroup * * I delete all unsolicited e-mail responses * "Paul Mac" wrote in message ... Hi All, This may seem really easy but it has elluded me for a while. I'm trying to figure out the correct syntax to capture an error when a collection key is not part of the collections contents, ie. if not colActiveCollection("NoSuchKey") IsNothing then .... end if The problem is that "NoSuchKey" is not in the collection. So it returns an Object Error and not Nothing. So how can I check the container without having to iterate over the entire collection looking for a match? I'm sure that the answer is below simple, so sorry for having to post such a simple question. Paul. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Correct Syntax | Excel Discussion (Misc queries) | |||
Correct VBA syntax | Excel Discussion (Misc queries) | |||
Can't get this syntax correct, please help. | Excel Programming | |||
ListBoxes - correct syntax | Excel Programming | |||
What is correct syntax for a CommandButton? | Excel Programming |