插入错误消息

时间:2018-07-05 19:36:20

标签: excel-vba vba excel

我想获得有关VBA代码的问题。

我有一个带有3条If-Then语句的代码。如果TextBox5 = 0; TextBox5 = 1;和TextBox5> 1 我需要插入一个错误消息,但我不知道每个If-Then语句的正确位置。 错误消息:“腿不存在。请检查旅行者,然后重试。”

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

0 个答案:

没有答案