abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,429
- Office Version
- 2019
- 2010
- Platform
- Windows
hi experts,
I hope find solution for this error application defined object defined error in this line
if I run this code works well
but if I run this code will shows error in above code
any help to fix it please?
I hope find solution for this error application defined object defined error in this line
VBA Code:
Set Rng = ws.Columns(2).Find(Sel, lookat:=xlWhole)
Code:
Private Sub ComboBox1_Change()
Dim ws As Worksheet
Dim Rng As Range
Dim Sel
Set ws = Sheets("BRANDS")
Sel = Me.ComboBox1.Value
If Sel <> "" Then
Set Rng = ws.Columns(2).Find(Sel, lookat:=xlWhole)
If Not Rng Is Nothing Then
Me.TextBox1.Value = ws.Cells(Rng.Row, "A")
Me.TextBox2.Value = ws.Cells(Rng.Row, "B")
Me.TextBox3.Value = ws.Cells(Rng.Row, "C")
Me.TextBox4.Value = ws.Cells(Rng.Row, "D")
Me.TextBox5.Value = ws.Cells(Rng.Row, "E")
End If
End If
End Sub
but if I run this code will shows error in above code
Code:
Private Sub CommandButton4_Click()
Dim lReply As VbMsgBoxResult
Dim ws As Worksheet
Dim strFind As String
strFind = Me.TextBox2.Value
If Len(strFind) = 0 Then
MsgBox "PLEASE WRITE THE CODE", vbExclamation, "Entry Required"
Me.TextBox2.SetFocus
Exit Sub
Else
lReply = MsgBox("Are you sure you want To delete variation?", vbCritical + vbYesNo, "Confirm")
If lReply = vbNo Then Exit Sub
End If
Set ws = Worksheets("brands")
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, "Not Found"
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