Excel 验证条目后无法提交用户表单 (VBA)

Excel Userform could not submit after validating entries (VBA)

我创建了一个用户表单,它将验证条目是否为电子邮件格式,是否为目录文件格式,是否填写了第一个 activity 以外的所有条目。但是,当我单击提交时,这些值不会添加到 excel 中。请告诉我,因为我真的迷路了。谢谢。

 Private Sub CommandButton1_Click()
 Dim tDate As Date
 Dim LastRow As Long
 Dim strValue As String
Dim msg As String
strValue = TextBox5.Value
 LastRow = ActiveSheet.Range("E65536").End(xlUp).Row + 1

If Not (TextBox5.Value = " " And TextBox1.Value = " " And (IsNull(ComboBox1.Value) = True) And (IsNull(ComboBox2.Value) = True) And TextBox6.Value = "" And TextBox4.Value = "" And (IsNull(MonthView1.Value) = True)) Then
   With CreateObject("vbscript.regexp")
     .Pattern = "^[\w-\.]+@([\w-]+\.)+[A-Za-z]{2,3}$"
     If .test(TextBox6.Value) Then
           'MsgBox "Added"
           GoTo GoToHere
     Else
          MsgBox "Invalid"
          Cancel = True
     End If
    End With
GoToHere:  ElseIf Not (InStr(strValue, "C:\") = 1) Then
                 MsgBox "Please start your directory with 'C:\'"



  Else
        ActiveSheet.Range("Q" & LastRow).Value = Me.TextBox5
        ActiveSheet.Range("E" & LastRow).Value = Me.TextBox1
        'tDate = CDate(TextBox2.Text)
        ActiveSheet.Range("G" & LastRow).Value = Me.MonthView1
        'Format(tDate, "dd/mm/yy")
        ActiveSheet.Range("H" & LastRow).Value = Me.ComboBox1
        ActiveSheet.Range("I" & LastRow).Value = Me.TextBox3
        ActiveSheet.Range("J" & LastRow).Value = Me.ComboBox2
        ActiveSheet.Range("M" & LastRow).Value = Me.TextBox4
        ActiveSheet.Range("C" & LastRow).Value = Me.TextBox7
        ActiveSheet.Range("S" & LastRow).Value = Me.TextBox6
 End If




End Sub

解决了!!!是的...这是我的解决方案。

Private Sub CommandButton1_Click()
     Dim tDate As Date
     Dim LastRow As Long
     Dim strValue As String
    Dim msg As String
    strValue = TextBox5.Value
     LastRow = ActiveSheet.Range("E65536").End(xlUp).Row + 1

    If Not (TextBox5.Value = " " And TextBox2.Value = " " And TextBox3.Value = " " And (IsNull(ComboBox1.Value) = True) And (IsNull(ComboBox2.Value) = True) And TextBox4.Value = "" And (IsNull(MonthView1.Value) = True)) Then
      'If Not (TextBox6.Value = "") Then
        With CreateObject("vbscript.regexp")
          .Pattern = "^[\w-\.]+@([\w-]+\.)+[A-Za-z]{2,3}$"
          If .test(TextBox4.Value) Then
                'MsgBox "Added"
                GoTo GoToHere
          Else
               MsgBox "Invalid"
               Cancel = True
          End If
         End With
    GoToHere:  If Not (InStr(strValue, "C:\") = 1) Then
                     MsgBox "Please start your directory with 'C:\'"



                Else
                      ActiveSheet.Range("Q" & LastRow).Value = Me.TextBox4
                      ActiveSheet.Range("E" & LastRow).Value = Me.TextBox2
                      'tDate = CDate(TextBox2.Text)
                      ActiveSheet.Range("G" & LastRow).Value = Me.MonthView1
                      'Format(tDate, "dd/mm/yy")
                      ActiveSheet.Range("H" & LastRow).Value = Me.ComboBox1
                      ActiveSheet.Range("I" & LastRow).Value = Me.TextBox3
                      ActiveSheet.Range("J" & LastRow).Value = Me.ComboBox2
                      ActiveSheet.Range("M" & LastRow).Value = Me.TextBox7
                      ActiveSheet.Range("C" & LastRow).Value = Me.TextBox1
                      ActiveSheet.Range("S" & LastRow).Value = Me.TextBox5
            End If

    End If


    End Sub