Answers for "vba collection key exists"

VBA
2

excel vba check if key is in collection

'A Dictionary is a better choice when you need to determine if a key 
'is already in the collection. But here is a VBA function that
'reports True or False for Collections:

Function KeyExists(key$, c As Collection)
  On Error Resume Next
  c.Item key
  KeyExists = Err = 0: Err.Clear
End Function

'--------------------------------------------------------------------

MsgBox KeyExists("Netflix", colFANG)
Posted by: Guest on April-29-2020
0

vba collection key exists

Public Function KeyExistsInCollection(ByVal key As String, _
                                      ByRef container As Collection) As Boolean
    With Err
        If container Is Nothing Then .Raise 91
        On Error Resume Next
        Dim temp As Variant
        temp = container.Item(key)
        On Error GoTo 0

        If .Number = 0 Then
            KeyExistsInCollection = True 
        ElseIf .Number <> 5 Then
            .Raise .Number
        End If
    End With
End Function
Posted by: Guest on February-05-2021

Code answers related to "VBA"

Browse Popular Code Answers by Language