SOLVED

deleting entire row using VBA

Copper Contributor

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.

2 Replies
best response confirmed by VI_Migration (Silver Contributor)
Solution

@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

Hi @Hans Vogelaar ,

Yes, That worked perfectly Thank you very much.

1 best response

Accepted Solutions
best response confirmed by VI_Migration (Silver Contributor)
Solution

@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

View solution in original post