Msgbox to show selected customers name in YES / NO message before its deleted

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
I have the code shown below "MINUS RED TEXT" which when i select a customer in column A it deletes it fine.
I need the user to check if he actually has selected the correct customer to delete so,
I added the code in RED to try & show a Msgbox with the customers name taken from what the user had selected in column A but im getting confused.


Rich (BB code):
Private Sub DeleteCustomer_Click()
    Dim tblName As String
    Dim tbl As ListObject
    Dim R As Long
    Dim lr As Long
    Dim i As Long
    Dim ActiveTableRow As Long
    
    If ActiveCell.Column = 1 Then
    MsgBox("DELETE CUSTOMER " & ActiveCell.Value & "?", vbYesNo + vbInformation, "DELETE CUSTOMER FROM DATABASE") = vbYes Then
        ActiveTableRow = Selection.Row - Selection.ListObject.Range.Row
        Selection.ListObject.ListRows(ActiveTableRow).Delete
        MsgBox "CUSTOMER NOW DELETED", vbInformation, "CUSTOMER DELETED MESSAGE"
        Else
        MsgBox "YOU MUST SELECT CUSTOMER IN COLUMN A", vbCritical, "NO CUSTOMER WAS SELECTED"
    End If
    
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I have managed to get this working BUT just need to now include customers name that has been selected in column A


Rich (BB code):
Private Sub DeleteCustomer_Click()
    Dim tblName As String
    Dim tbl As ListObject
    Dim R As Long
    Dim lr As Long
    Dim i As Long
    Dim ActiveTableRow As Long
    
    If ActiveCell.Column = 1 Then
        If MsgBox("DELETE CUSTOMER FROM DATABASE" & " ?", vbYesNo + vbInformation, "DELETE CUSTOMER FROM DATABASE") = vbNo Then
        Exit Sub
        Else
        End If
        ActiveTableRow = Selection.Row - Selection.ListObject.Range.Row
        Selection.ListObject.ListRows(ActiveTableRow).Delete
        MsgBox "CUSTOMER NOW DELETED", vbInformation, "CUSTOMER DELETED MESSAGE"
        Else
        MsgBox "YOU MUST SELECT CUSTOMER IN COLUMN A", vbCritical, "NO CUSTOMER WAS SELECTED"
    End If
    
End Sub
 
Upvote 0
The only things missing from your original attempt was the word If at the start of the line in red, and a second End If line at the end of the code.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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