Robert Allan
New Member
- Joined
- Mar 30, 2020
- Messages
- 19
- Office Version
- 365
- Platform
- Windows
I am creating a Data Entry Form in Excel and I am having a problem deleting a record. My Subs Save, Modify and Reset are all working fine, but I keep getting the Runtime error 1004 “method of range class failed”. The following is my sub-routine:
Please Help!
VBA Code:
Sub DeleteRecord()
Dim iRow As Long
Dim iRec As Long
iRec = Application.InputBox("Please enter Rec No. to delete the record.", "Delete Record?", , , , , , 1)
If iRow = 2 then
iRec = 1
End If
On Error Resume Next
iRow = Application.WorksheetFunction.IfError(Application.WorksheetFunction.Match(iRec, Sheets("Data 2020").Range("A:A"), 0), 0)
On Error GoTo 0
If iRow = 0 Then
MsgBox "No record found", vbOKOnly + vbCritical, "No Record"
Exit Sub
End If
Sheets("Data 2020").Cells(iRow, 1).EntireRow.Delete shift:=xlUp
End Sub
Please Help!
Last edited by a moderator: