Userform delete function VBA run-time error ’94’

  Kiến thức lập trình

I am working on a VBA userform so you can enter/delete data on a table, I had no issues with the adding data code, but when it came to deleting the data I’m running into error 94. I would really appreciate some insight on what’s going on, thank you!

For Reference, the table is named ‘Table2’
The worksheet is named ‘VendorList’
The form is named ‘UserForm1’
The button is named ‘cmdDelete’

Private Sub UserForm1_Initialize()

lstDisplay.List = Sheets("VendorList").ListObjects(1).DataBodyRange.Value

End Sub
Private Sub cmdDelete_Click()
    Dim myTab As ListObject
    Dim mySt As String, fndmySt As Range

    If lstDisplay.ListIndex <> -1 Then
            If Me.lstDisplay.ListIndex > -1 Then
                     mySt = ""
                If mySt = "" Then
                        mySt = lstDisplay.Value
                End If
                MsgBox "Please select a row!", vbExclamation
                Exit Sub
            End If
        Set myTab = Sheets("VendorList").ListObjects(1)
    With myTab.ListColumns(1).Range
        Set fndmySt = .Find(What:=mySt, LookIn:=xlValues, LookAt:=xlWhole, _
            SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    End With
            If Not fndmySt Is Nothing Then
                myTab.ListRows(fndmySt.Row - myTab.HeaderRowRange.Row).Range.Delete
            End If
        lstDisplay.List = myTab.DataBodyRange.Value
    End If
End Sub

New contributor

xCellent is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website