Excel 确保userform上的combobox和textbox不为空
我想确保combobox和textbox不是空的。如果为空,则提示以确保它不是空的 我试过打圈Excel 确保userform上的combobox和textbox不为空,excel,vba,userform,Excel,Vba,Userform,我想确保combobox和textbox不是空的。如果为空,则提示以确保它不是空的 我试过打圈 Private Sub submitactive_click() Sheets("ComplaintsData").Activate Sheets("ComplaintsData").Unprotect emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1 If (cmbRegion.Value = "") Th
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
< >代码不会提交表单,但是当我在空白字段中输入数据时,子不再工作。 < P>这是因为您在错误的地方有了<代码> Exit Sub <代码>。当代码运行时,它会检查两个控件是否为空。如果其中一个为空,则会显示一条消息,然后它会简单地退出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
这是因为
Exit Sub
位于错误的位置。当代码运行时,它会检查两个控件是否为空。如果其中一个为空,则会显示一条消息,然后它会简单地退出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