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

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,683
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,099
Messages
6,170,111
Members
452,302
Latest member
TaMere

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