0
我在Excel 2010中有一個用戶表單。有8個文本框。他們並不需要填寫提交數據。如果所有8個文本框均爲空白,則會出現一個msgbox。以下是我的代碼。有沒有更優雅的編碼方式?謝謝。vba用戶表單輸入錯誤檢查
Dim A
Dim B
Dim C
Dim D
Dim E
Dim F
Dim G
Dim H
If TextBox1.Text = "" Then
A = 0
Else
A = 1
End If
If TextBox2.Text = "" Then
B = 0
Else
B = 1
End If
If TextBox3.Text = "" Then
C = 0
Else
C = 1
End If
If TextBox4.Text = "" Then
D = 0
Else
D = 1
End If
If TextBox5.Text = "" Then
E = 0
Else
E = 1
End If
If TextBox6.Text = "" Then
F = 0
Else
F = 1
End If
If TextBox7.Text = "" Then
G = 0
Else
G = 1
End If
If TextBox8.Text = "" Then
H = 0
Else
H = 1
End If
If A + B + C + D + E + F + G + H = 0 Then
MsgBox " Enter Some Data,", vbOKOnly + vbCritical, "ERROR!"
Else
'.....rest of code.....
取而代之的是如果A + B + C + D + E + F + G + H = 0那麼你可以直接使用TextBox值:如果TextBox1.Text和TextBox2.Text& ..&TextBox8.Text =「」Then' –