ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Hi,
Confused myself with these Yes No msgboxes.
Code in use shown below
This is how it should work,
I type a value in TextBox1 & results shown in Listbox1.
I make a listbox selection
I see the msgbox Are you sre you wish to delete customer ?
Selecting No should just stop & close down the userform
Selecting Yes should delete that customers row on my worksheet
Selecting No goes straight to msgbox Delete another customer ?
Confused myself with these Yes No msgboxes.
Code in use shown below
This is how it should work,
I type a value in TextBox1 & results shown in Listbox1.
I make a listbox selection
I see the msgbox Are you sre you wish to delete customer ?
Selecting No should just stop & close down the userform
Selecting Yes should delete that customers row on my worksheet
Selecting No goes straight to msgbox Delete another customer ?
Rich (BB code):
Private Sub ListBox1_Click()
Dim answer As Integer
Range("A" & ListBox1.List(ListBox1.ListIndex, 1)).Select
Dim c As Range
With Sheets("DATABASE")
Set c = .Range("A:A").Find(What:=ListBox1.Value, _
After:=.Range("A5"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
If Not c Is Nothing Then
If MsgBox("ARE YOU SURE YOU WISH TO DELETE CUSTOMER " & ListBox1.Text & "?", vbYesNo + vbInformation, "DELETE CUSTOMER FROM DATABASE") = vbYes Then
Rows(c.Row).EntireRow.Delete
MsgBox "THE CUSTOMER " & Me.ListBox1.Value & " HAS NOW BEEN DELETED", vbInformation, "CUSTOMER DELETED MESSAGE"
End If
answer = MsgBox("DELETE ANOTHER CUSTOMER ?", vbYesNo + vbQuestion)
If answer = vbYes Then
TextBox1.Value = ""
End If
Else
MsgBox "THE CUSTOMER " & Me.ListBox1.Value & " WAS NOT DELETED", vbInformation, "CUSTOMER WAS NOT DELETED MEAASGE"
Range("A6").Select
End If
Set c = Nothing
End Sub