I have an issue with VBA code that I would like to get help with.
I have a code with 3 If-Then Statements. IF TextBox5 = 0; TextBox5 = 1; and TextBox5 > 1 I need to insert an error msg but I don't know what would be the correct location for each of the If-Then Statements. Error msg: "The Leg Doesn't Exist. Please Check The Traveller And Try Again."
Private Sub TextBox5_AfterUpdate()
On Error Resume Next
If TextBox5.Value = 0 And Not IsEmpty(TextBox5.Value) Then
Set MyRange = ActiveWorkbook.Worksheets("Raw Data").Range("Table_Query_from_Visual654[base_id]")
For Each c In MyRange
If c.Value Like UCase(TextBox4.Value) Then
If Sheet1.Cells(c.Row, 4) = TextBox5.Value Then
TextBox13.Value = Sheet1.Cells(c.Row, 5)
TextBox14.Value = Sheet1.Cells(c.Row, 6)
End If
End If
Next
End If
If TextBox5.Value = 1 And Not IsEmpty(TextBox5.Value) Then
Set MyRange = ActiveWorkbook.Worksheets("Raw Data").Range("Table_Query_from_Visual654[base_id]")
For Each c In MyRange
If c.Value Like UCase(TextBox4.Value) Then
If Sheet1.Cells(c.Row, 4) = 0 Then ' Set it to 0 if 1 is enetered into TextBox5
TextBox13.Value = Sheet1.Cells(c.Row, 5)
TextBox14.Value = Sheet1.Cells(c.Row, 6)
End If
End If
Next
End If
If TextBox5.Value > 1 And Not IsEmpty(TextBox5.Value) Then
Set MyRange = ActiveWorkbook.Worksheets("Raw Data").Range("Table_Query_from_Visual654[base_id]")
For Each c In MyRange
If c.Value Like UCase(TextBox4.Value) Then
If Sheet1.Cells(c.Row, 4) = TextBox5.Value Then
TextBox13.Value = Sheet1.Cells(c.Row, 9)
Else
TextBox14.Value = ""
End If
End If
Next
End If
Worksheets("Cost Analysis").Range("B1").Value = UCase(TextBox5.Value)
Call TextBox6_AfterUpdate
Call TextBox9_data
End Sub