abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,429
- Office Version
- 2019
- 2010
- Platform
- Windows
hi
I face problem is not clear for me . I put message in beggining of the code when textbox2 is empty , then pop up message "PLEASEE WRITE THE CODE" and if it's not .should continue the procedure and show the next message "Are you sure you want to delete variation?", vbCritical + vbYesNo , but the first message shows whether textbox2 is empty or not .
any help to fix it , please ?
I face problem is not clear for me . I put message in beggining of the code when textbox2 is empty , then pop up message "PLEASEE WRITE THE CODE" and if it's not .should continue the procedure and show the next message "Are you sure you want to delete variation?", vbCritical + vbYesNo , but the first message shows whether textbox2 is empty or not .
VBA Code:
Private Sub CommandButton4_Click()
Dim lReply As Long
Dim ws As Worksheet
Dim strFind As String
If strFind = "" Then MsgBox "PLEASEE WRITE THE CODE", vbExclamation
Exit Sub
lReply = MsgBox("Are you sure you want to delete variation?", vbCritical + vbYesNo)
If lReply = vbNo Then Exit Sub
Set ws = Worksheets("sheet1")
strFind = Me.TextBox2.Value
With ws.UsedRange.Columns(2)
If WorksheetFunction.CountIf(.Cells, strFind) <> 0 Then
.Cells.Find(What:=strFind, After:=.Cells(1, 1), MatchCase:=True).EntireRow.Delete
Else
MsgBox "Could not find " & strFind & " on " & ws.Name, vbCritical
Exit Sub
End If
End With
strFind = "VO" & strFind
On Error Resume Next
Application.DisplayAlerts = False
Sheets(strFind).Delete
Application.DisplayAlerts = True
On Error GoTo 0
'Close Form
Unload Me
End Sub