Check if exists in List

Vishesh's picture
This utility demonstrates how you can use the match function to find a string even in a listbox or a dropdown.
Sub Check()
 
    If blnExists(Sheet1.Range("C13").Value, Sheet1.ListBoxes("List Box 1")) = True Then
 
        MsgBox "Exists"
 
    Else
 
        MsgBox "Does not exists"
 
    End If
 
End Sub
 
 
 
Function blnExists(strFind As String, lst As ListBox) As Boolean
 
    On Error Resume Next
 
    blnExists = (Application.WorksheetFunction.Match(strFind, lst.List, 0) > 0)
 
    If Err.Number > 0 Then blnExists = False
 
    On Error GoTo 0
 
End Function
AttachmentSize
ExistsInList.xls27.5 KB