Forum Discussion
Rory3
Feb 04, 2022Copper Contributor
deleting entire row using VBA
HI all.
I'm trying to make a form for data entry and I need to write a code for the delete button on the form. I have copied the following form my excel sheet.
Sub ENTRY_DELETE() With Sheet1 If MsgBox("ARE YOU SURE YOU WANT TO DELETE THIS ENTRY?", vbYesNo, "DELETE ENTRY") = vbNo Then Exit Sub
If .Range("B3") = Empty Then Exit Sub EntryRow = .Range("B3").Value
.Range(EntryRow & "." & EntryRow).EntireRow.Delete .Range("D13").Select
End With
End Sub
Im very new to this so any help would be appreciated.
Thanks.
Like this:
Sub ENTRY_DELETE() Dim EntryRow As Long If MsgBox("ARE YOU SURE YOU WANT TO DELETE THIS ENTRY?", vbYesNo, "DELETE ENTRY") = vbNo Then Exit Sub With Sheet1 If .Range("B3") = "" Then Exit Sub EntryRow = .Range("B3").Value .Range("A" & EntryRow).EntireRow.Delete End With End Sub
2 Replies
Sort By
Like this:
Sub ENTRY_DELETE() Dim EntryRow As Long If MsgBox("ARE YOU SURE YOU WANT TO DELETE THIS ENTRY?", vbYesNo, "DELETE ENTRY") = vbNo Then Exit Sub With Sheet1 If .Range("B3") = "" Then Exit Sub EntryRow = .Range("B3").Value .Range("A" & EntryRow).EntireRow.Delete End With End Sub
- Rory3Copper Contributor
Hi HansVogelaar ,
Yes, That worked perfectly Thank you very much.