验证条目(VBA)后,Excel Userform无法提交

时间:2015-03-13 03:17:57

标签: excel-vba vbscript vba excel

我创建了一个userform,用于验证条目是否是电子邮件格式,如果是目录文件格式,如果所有的东西都填充了第一个活动。但是,当我单击“提交”时,值不会添加到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

1 个答案:

答案 0 :(得分:0)

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

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