How to delete rows from active rows and show confirm msgBox?

oshi1998

New Member
Joined
Jan 13, 2021
Messages
6
Platform
  1. Windows
Sorry, My english isn't that good. I'm still practicing.

Okay. Hello everyone. I'm a beginner, I need to know source code for this (VBA Macro)

1111.png

Step1 : User select rows need to delete data.
Step2 : User Click 'Delete' Button and show confirm MsgBox and in msgBox show list Id for delete
Example : "Are you sure to delete data ID: 2,3 ?"
Step3 : If User click OK -> Delete rows 3 and 4.

Help me pls. thank you.
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,139
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Sub oshi()
   Dim x As Variant
   With Selection
      If .Rows.Count = 1 Then
         x = .Columns(1).Value
      Else
         x = Join(Application.Transpose(.Columns(1)), ", ")
      End If
      If MsgBox("Are you sure to delete data ID: " & x & "?", vbYesNo) = vbYes Then
         .EntireRow.Delete
      End If
   End With
End Sub
 
Solution

oshi1998

New Member
Joined
Jan 13, 2021
Messages
6
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Sub oshi()
   Dim x As Variant
   With Selection
      If .Rows.Count = 1 Then
         x = .Columns(1).Value
      Else
         x = Join(Application.Transpose(.Columns(1)), ", ")
      End If
      If MsgBox("Are you sure to delete data ID: " & x & "?", vbYesNo) = vbYes Then
         .EntireRow.Delete
      End If
   End With
End Sub
Thank you very much it works 100% I will learn about this code myself. How it work 🙏
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,139
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,995
Messages
5,599,256
Members
414,299
Latest member
thenewworld

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
Top