- 帖子
- 103
- 主題
- 30
- 精華
- 0
- 積分
- 139
- 點名
- 0
- 作業系統
- wondows XP
- 軟體版本
- office 2007
- 閱讀權限
- 20
- 性別
- 男
- 來自
- 彰化
- 註冊時間
- 2013-2-21
- 最後登錄
- 2015-6-26
|
想請問大大
我在表單TextBox 設置若是空白就出現警告視窗
但只有對於第一個欄位有用
如果第一個填完後跳過第二個驗證空白的TextBox
直接填上第三個再按Button
照樣會填進去,警告視窗也會跑出來
有沒有辦法驗證資料齊全後才進行填入的動作呢?
我寫的程式如下
=========================
Private Sub CommandButton1_Click()
Call test
End Sub
Sub test()
Dim A As Range
If Application.CountBlank(Sheet1.Range("A1:A99")) = 0 Then
Sheet1.[A100] = ComboBox1.Value
Else
Set A = [A3]
Do Until A = ""
Set A = A.Offset(1, 0)
Loop
A.Value = ComboBox1.Value
End If
If ComboBox1.ListIndex = -1 Then MsgBox "空白未填寫 !!": Exit Sub
a1 = UserForm.TextBox1.Value
If Application.CountBlank([B1:B99]) = 0 Then Range("B100") = a1: Exit Sub
For Each A In [B3:B99]
If A = "" Then
A.Value = a1
Exit For
End If
Next
If .a1 = "" Then MsgBox "空白未填寫 !!": Exit Sub
a2 = UserForm.TextBox2.Value
If Application.CountBlank([C1:C99]) = 0 Then Range("C100") = a2: Exit Sub
For Each A In [C1:C99]
If A = "" Then
A.Value = a2
Exit For
End If
Next
If .a2= "" Then MsgBox "空白未填寫 !!": Exit Sub
End Sub |
|