返回列表 上一主題 發帖

資料輸入出現警告視窗要怎麼停止?

資料輸入出現警告視窗要怎麼停止?

想請問大大
我在表單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
Jared

回復 2# mark15jill


    大大~ 我後來是先把欄位都填上預設值
   讓使用者即使忘記填上數值
   也能夠先有資料對應欄位
   即使沒填上也不會出現錯誤 (^口^)
Jared

TOP

        靜思自在 : 不要隨心所欲,要隨心教育自己。
返回列表 上一主題