确保用户窗体上的组合框和文本框不为空
Ensure combobox and textbox on a userform are not blank
我想确保组合框和文本框不为空。如为空,提示确保不留空
我试了一个循环
Private Sub submitactive_click()
Sheets("ComplaintsData").Activate
Sheets("ComplaintsData").Unprotect
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
If (cmbRegion.Value = "") Then
MsgBox "Need to select Region"
End If
If (tbObjLink.Value = "") Then
MsgBox "Need to enter Objective Link"
End If
Exit Sub
Cells(emptyRow, 2).Value = emptyRow - 1
Cells(emptyRow, 1).Value = dtdate.Value
Cells(emptyRow, 3).Value = cmbChannel.Value
Cells(emptyRow, 4).Value = cmbIssue.Value
Cells(emptyRow, 5).Value = cmbSource.Value
Cells(emptyRow, 6).Value = tbname.Value
Cells(emptyRow, 7).Value = ccdemail.Value
Cells(emptyRow, 8).Value = ccdphone.Value
Cells(emptyRow, 9).Value = cmbRegion.Value
Cells(emptyRow, 10).Value = cmbBusinessGroup.Value
Cells(emptyRow, 11).Value = cmbBusinessUnit.Value
Cells(emptyRow, 12).Value = tbreferredby.Value
Cells(emptyRow, 13).Value = tbaction.Value
Cells(emptyRow, 14).Value = tbnotes.Value
Cells(emptyRow, 15).Value = tbObjLink.Value
Cells(emptyRow, 16).Formula = "=TEXT(A" & emptyRow & ", ""mmm yyyy"")"
MsgBox "Complaints Information Submitted"
Sheets("Forms").Activate
Sheets("ComplaintsData").Protect AllowFiltering:=True
ActiveWorkbook.Save
Call UserForm_Initialize
End Sub
代码不会提交表单,但是当我在空白字段中输入数据时,子程序不再有效。
那是因为你把 Exit Sub
放错了地方。当您的代码运行时,它会检查任一控件是否为空。如果其中一个为空,则会显示一条消息,然后它会简单地退出子程序,而不管其中一个或两者是否为空。尝试这样的事情...
If (cmbRegion.Value = "") Then
MsgBox "Need to select Region"
Exit Sub
End If
If (tbObjLink.Value = "") Then
MsgBox "Need to enter Objective Link"
Exit Sub
End If
我想确保组合框和文本框不为空。如为空,提示确保不留空
我试了一个循环
Private Sub submitactive_click()
Sheets("ComplaintsData").Activate
Sheets("ComplaintsData").Unprotect
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
If (cmbRegion.Value = "") Then
MsgBox "Need to select Region"
End If
If (tbObjLink.Value = "") Then
MsgBox "Need to enter Objective Link"
End If
Exit Sub
Cells(emptyRow, 2).Value = emptyRow - 1
Cells(emptyRow, 1).Value = dtdate.Value
Cells(emptyRow, 3).Value = cmbChannel.Value
Cells(emptyRow, 4).Value = cmbIssue.Value
Cells(emptyRow, 5).Value = cmbSource.Value
Cells(emptyRow, 6).Value = tbname.Value
Cells(emptyRow, 7).Value = ccdemail.Value
Cells(emptyRow, 8).Value = ccdphone.Value
Cells(emptyRow, 9).Value = cmbRegion.Value
Cells(emptyRow, 10).Value = cmbBusinessGroup.Value
Cells(emptyRow, 11).Value = cmbBusinessUnit.Value
Cells(emptyRow, 12).Value = tbreferredby.Value
Cells(emptyRow, 13).Value = tbaction.Value
Cells(emptyRow, 14).Value = tbnotes.Value
Cells(emptyRow, 15).Value = tbObjLink.Value
Cells(emptyRow, 16).Formula = "=TEXT(A" & emptyRow & ", ""mmm yyyy"")"
MsgBox "Complaints Information Submitted"
Sheets("Forms").Activate
Sheets("ComplaintsData").Protect AllowFiltering:=True
ActiveWorkbook.Save
Call UserForm_Initialize
End Sub
代码不会提交表单,但是当我在空白字段中输入数据时,子程序不再有效。
那是因为你把 Exit Sub
放错了地方。当您的代码运行时,它会检查任一控件是否为空。如果其中一个为空,则会显示一条消息,然后它会简单地退出子程序,而不管其中一个或两者是否为空。尝试这样的事情...
If (cmbRegion.Value = "") Then
MsgBox "Need to select Region"
Exit Sub
End If
If (tbObjLink.Value = "") Then
MsgBox "Need to enter Objective Link"
Exit Sub
End If