I have code I copied from a tutorial that is no longer available. When I use the code I get the 1004 error "Delete Method of Range Class Failed. I have nailed it down to th this line: findvalue.EntireRow.Delete, but I can't figure out why or how to get passed it. My worksheet is an employee roster. THe search is looking for a record number returned from a search to a list box in a user form. I double click the record and it fills 30 controls in the user form. I should then be able to delete the record selected based on the record number in control "Emp1". The code requires that the position number "Emp4" and record number "Emp1" be present to proceed.
The code is posted below. Any education and resolution is very welcomed at this point.
Thank you
The code is posted below. Any education and resolution is very welcomed at this point.
Thank you
VBA Code:
Private Sub cmdDeleteEmp_Click()
'declare the variables
Dim findvalue As Range
Dim cDelete As VbMsgBoxResult
Dim cNum As Integer
'error statement
On Error GoTo errHandler:
'check for values
If Emp1.Value = "" Or Emp4.Value = "" Then
MsgBox "There is no data to delete"
Exit Sub
End If
'give the user a chance to change their mind
cDelete = MsgBox("Are you sure that you want to delete this record", vbYesNo + vbDefaultButton2, "click OK to detete this record")
If cDelete = vbYes Then
'find the row
Set findvalue = Sheet7.Range("A:A").Find(What:=Emp1, LookIn:=xlValues)
findvalue.EntireRow.Delete 'error line
End If
'clear the controls
cNum = 30
For x = 1 To cNum
Me.Controls("Emp" & x).Value = ""
Next
'run the filter
AdvFilterOutdata
'add the values to the listbox
lstEmployee.RowSource = ""
lstEmployee.RowSource = "Outdata"
'error block
On Error GoTo 0
Exit Sub
errHandler::
MsgBox "An Error has Occurred " & vbCrLf & "The error number is: " _
& Err.Number & vbCrLf & Err.Description & vbCrLf & _
"Please notify the administrator"
End Sub