Hi I have this a userform where users enter data. first they enter a string of number into textbox4, and macro checks against the worksheet if this number exists. If it exists, then enable combobox3. if it does not exists and combobox2 selection is "Others", then disable combobox3. this is the code im using and I cant get it to work. Can anyone help please?
Private Sub TextBox4_Change()
Dim frow
If TextBox4.Text = "" Then
TextBox5.Text = ""
End If
With Sheets("Sheet1")
frow = Application.Match((TextBox4.Text), .Columns(1), 0)
If IsError(frow) And ComboBox2.Value <> "Others" Then
TextBox5.Text = ""
CommandButton4.Enabled = True
ComboBox3.Enabled = True
End If
End With
With Sheets("Sheet1")
frow = Application.Match((TextBox4.Text), .Columns(1), 0)
If IsError(frow) And ComboBox2.Value = "Others" Then
ComboBox3.Enabled = False
End If
End With
With Sheets("Sheet1")
frow = Application.Match((TextBox4.Text), .Columns(1), 0)
If Not IsError(frow) Then
If .Cells(frow, 5).Value <> vbNullString And .Cells(frow, 7).Value = vbNullString Then
TextBox5.Text = "Case is already in storage. Placed in " & .Cells(frow, 2).Value & " in Division " & .Cells(frow, 3).Value & " Box " & .Cells(frow, 4).Value & " by " & .Cells(frow, 5).Value & " on " & .Cells(frow, 6).Value: foundrow = frow
CommandButton4.Enabled = False
ComboBox1.Enabled = False
ComboBox2.Enabled = False
ComboBox3.Enabled = False
ElseIf .Cells(frow, 12).Value <> vbNullString And .Cells(frow, 14).Value = vbNullString Then
TextBox5.Text = "Case is already in storage. Placed in " & .Cells(frow, 9).Value & " in Division " & .Cells(frow, 10).Value & " Box " & .Cells(frow, 11).Value & " by " & .Cells(frow, 12).Value & " on " & .Cells(frow, 13).Value: foundrow = frow
CommandButton4.Enabled = False
ComboBox1.Enabled = False
ComboBox2.Enabled = False
ComboBox3.Enabled = False
ElseIf .Cells(frow, 14).Value <> vbNullString Then
TextBox5.Text = "Case returned by " & .Cells(frow, 14).Value & " on " & .Cells(frow, 15).Value: foundrow = frow
CommandButton4.Enabled = False
ComboBox1.Enabled = False
ComboBox2.Enabled = False
ComboBox3.Enabled = False
Else
TextBox5.Text = ""
CommandButton4.Enabled = True
ComboBox1.Enabled = True
ComboBox2.Enabled = True
ComboBox3.Enabled = True
End If
End If
End With
End Sub
Bookmarks