MsgBox advice for name to be shown after deletion from combobox

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Evening,
I am using the code shown below.


I have a combobox which has customers names in it.
I run the code supplied below which deletes the selected name from my worksheet & then it doesnt appear in the combobox again as you would expect.
My question relates to the code shown in Red.

I am expecting that once the name is deleted i then see this msgbox.
I expect to then see SUCESSFUL DELETION OF CUSTOMER TOM JONES

TOM JONES being the customer that was selected in the combobox.

So is my code incorrect OR is this not possible because its been deleted how will it advise you of the name if it isnt there ?
I dont see an error message etc & thought by adding the code & NameForDateEntryBox.Value would give me what i would like to see.


Rich (BB code):
Private Sub DeleteTestName_Click()
    Dim lRow As Long, ws As Worksheet, i As Long
    Set ws = Application.Worksheets("POSTAGE")
    If NameForDateEntryBox.Value = "" Then
        MsgBox "YOU MUST SELECT A CUSTOMER FIRST", vbCritical, "SELECT CUSTOMER FIRST MESSAGE"
        Me.NameForDateEntryBox.SetFocus
        
        Exit Sub
        
    End If
    If MsgBox("DELETE CUSTOMER " & NameForDateEntryBox.Value & " ?", vbCritical + vbYesNo + vbDefaultButton2, "DELETE CONFIRMATION MESSAGE") = vbNo Then
        TextBox2.SetFocus
        NameForDateEntryBox = ""
        
        Exit Sub
    Else
        lRow = ws.Cells(Rows.Count, 2).End(xlUp).Row '  2 COLUMN B
        For i = 1 To lRow
            If ws.Cells(i, 2).Value = Me.NameForDateEntryBox.List(Me.NameForDateEntryBox.ListIndex) Then   ' 2 IS COLUMN B
                Rows(i).Select
                Rows(i).Delete
                Call populate
                Application.ScreenUpdating = True
                
                MsgBox "SUCESSFUL DELETION OF CUSTOMER " & NameForDateEntryBox.Value, vbInformation, "DELETE CONFIRMATION MESSAGE"
                
                Exit For
            End If
        Next i
    End If
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try using a variable to store the name (not tested):
VBA Code:
Private Sub DeleteTestName_Click()
    Dim lRow As Long, ws As Worksheet, i As Long
    Dim StoredName As String
    
    Set ws = Application.Worksheets("POSTAGE")
    If NameForDateEntryBox.Value = "" Then
        MsgBox "YOU MUST SELECT A CUSTOMER FIRST", vbCritical, "SELECT CUSTOMER FIRST MESSAGE"
        Me.NameForDateEntryBox.SetFocus
        
        Exit Sub
    End If
    
    StoredName = NameForDateEntryBox.Value
    
    If MsgBox("DELETE CUSTOMER " & StoredName & " ?", vbCritical + vbYesNo + vbDefaultButton2, "DELETE CONFIRMATION MESSAGE") = vbNo Then
        TextBox2.SetFocus
        NameForDateEntryBox = ""
        
        Exit Sub
    Else
        lRow = ws.Cells(Rows.Count, 2).End(xlUp).Row '  2 COLUMN B
        For i = 1 To lRow
            If ws.Cells(i, 2).Value = Me.NameForDateEntryBox.List(Me.NameForDateEntryBox.ListIndex) Then   ' 2 IS COLUMN B
                Rows(i).Select
                Rows(i).Delete
                Call populate
                Application.ScreenUpdating = True
                
                MsgBox "SUCESSFUL DELETION OF CUSTOMER " & StoredName, vbInformation, "DELETE CONFIRMATION MESSAGE"
                
                Exit For
            End If
        Next i
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,867
Messages
6,122,002
Members
449,059
Latest member
mtsheetz

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