Determining whether an object is a member of a collection in VBA

前端 未结 15 1833
自闭症患者
自闭症患者 2020-11-27 05:35

How do I determine whether an object is a member of a collection in VBA?

Specifically, I need to find out whether a table definition is a member of the TableDe

15条回答
  •  悲&欢浪女
    2020-11-27 05:53

    I wrote this code. I guess it can help someone...

    Public Function VerifyCollection()
        For i = 1 To 10 Step 1
           MyKey = "A"
           On Error GoTo KillError:
           Dispersao.Add 1, MyKey
           GoTo KeepInForLoop
    KillError: 'If My collection already has the key A Then...
            count = Dispersao(MyKey)
            Dispersao.Remove (MyKey)
            Dispersao.Add count + 1, MyKey 'Increase the amount in relationship with my Key
            count = Dispersao(MyKey) 'count = new amount
            On Error GoTo -1
    KeepInForLoop:
        Next
    End Function
    

提交回复
热议问题