Here is a modification to show only one record to delete in case only one row is selected.
Sub RowDelete()
Set inter_sect = Application.Intersect(Selection, Range("A6", Cells(Rows.Count, 11).End(xlUp)))
If Not inter_sect Is Nothing Then
With inter_sect 'use inter_sect instead of ActiveCell to allow multiple cells
If inter_sect.Count = 1 Then
If MsgBox("Are you sure you want to delete record number " _
& Range("A" & .Row), vbYesNo, "Delete row?") = vbYes Then
.EntireRow.Delete
End If
Else
If MsgBox("Are you sure you want to delete record number " _
& Range("A" & .Row) & ", " & Range("A" & .Row + .Count - 1) & "?" _
, vbYesNo, "Delete row?") = vbYes Then
.EntireRow.Delete
End If
End If
End With
Else
MsgBox "You must select a record to be deleted", vbInformation, "NO RECORD SELECTED"
End If
End Sub
In the code, I use column K to find the last row of the table because it is also the last column and that we want to be sure any selected cells of the table will trigger the deletion. You can replace the SET line of code with this one if you like. it defines a range from cell A6 to cell K?. The row number is found by looking at the last non-empty cell in a column (actually it is column 1) you select yourself a column which you are sure there will never be something below your table. This is not affected by the cells' content. It can be either a fixed value or a formula.
Set inter_sect = Application.Intersect(Selection, Range("A6:K" & Cells(Rows.Count, 1).End(xlUp).Row))
Bookmarks