Hello,

I have the following code:

Private Sub UserForm_Initialize()

Dim rRng As Range, r As Range, rSortCr As String

Set rRng = Sheets("LiveCustomers").Range("Table_Query_from_Orderwise7[cd_statement_name]")
rSortCr = UCase(ActiveCell.Value)

For Each r In rRng
    If InStr(UCase(r), rSortCr) Then Me.ListBox1.AddItem r.Value
Next r

If Me.ListBox1.ListCount = 1 Then
    Me.ListBox1.ListIndex = 0
    Selection.Value = Me.ListBox1.Value
    Unload Me
End If

End Sub
However, if there is only one entry that matches the search criteria put into the active cell, then it brings up an error saying "runtime error 91, object variable or with block variable not set". It errors on this piece of code:

    If InStr(UCase(r), rSortCr) Then Me.ListBox1.AddItem r.Value
Next r
However when there is more than 1 entry that matches the criteria, it works perfectly

Can anyone help?