Macro to delete entire row and tell me what row i'm deleteing

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I want a macro that can do this,
I select a cell,
run the macro and it deletes entire row of cell i selected, but before, i get a message box saying "This will delete row 56" (or whichever row ive selected) and say "Which is client" and the data from that row column H, do you wish to proceed? yes/no

Please help iif you can

Thanks

Tony
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi tonywatsonhelp,

This code should do what you have asked for:

Code:
Sub DeleteActiveCellsRow()
    Dim activeRowNumber As Long
    Dim iAns As VbMsgBoxResult
    
    activeRowNumber = ActiveCell.Row
    Rows(activeRowNumber).Select
    
    iAns = MsgBox("This will delete row " & activeRowNumber & " Which is client " & _
    Cells(activeRowNumber, 8) & " do you wish to proceed?", vbYesNo + vbQuestion, "Delete Row?")
    
    If iAns = vbYes Then
        Selection.Delete Shift:=xlUp
    Else
        'Do nothing
    End If
End Sub
 
Last edited:
Upvote 0
Here is another way -- to work with Events - using the Before Right-Click Worksheet Event
Paste the below code into your sheets code window.
If you have a header row(s) - watch in code line 4 where I use Row # (This is Excel Row Number) change accordingly.....

Try it in a BACK-UP copy of your file before moving forward...

Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Application.Intersect(Target, Columns("H")) Is Nothing Then Exit Sub
Cancel = True
res = MsgBox("You are about to Delete Row #: " & Target.Row & vbNewLine & _
    "with the Client name: " & Target.Value & "." & vbNewLine _
    & "Do you wish to proceed?", vbYesNo + vbQuestion)
    If res = 6 Then
        Target.EntireRow.Delete
    End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,030
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top