Forum Discussion

Rory3's avatar
Rory3
Copper Contributor
Feb 04, 2022
Solved

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.

  • Rory3 

    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

  • Rory3 

    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

Resources