返回列表 上一主題 發帖

一個清單驗證問題

一個清單驗證問題

請問各位先進
我下列程式碼有哪裡錯誤嗎?
為何我輸入清單以外的文字
無法出現錯誤訊息

With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=" & bb
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With

回復 2# GBKEE


    感謝G大的回覆
我去試試看

TOP

回復 2# GBKEE


    再請問G大一個問題
陣列BB(30)內30可以是變數嗎?

TOP

回復 5# GBKEE

請問G大我執行到這一段會出現錯誤
Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=" & bb
會出現錯誤

    Sub 清單明細()
If ActiveCell.Cells.Column <> "4" Then Exit Sub
aa = ActiveCell
If aa = "" Then Exit Sub

g = Worksheets("清單明細").Cells(65536, 1).End(xlUp).Row
For i = 1 To g
If Worksheets("清單明細").Cells(i, 1) = aa Then
b = 0
    For a = 4 To 34
        kk(b) = Worksheets("清單明細").Cells(i, a)
        b = b + 1
    Next a
bb = Join(kk, ",")

'bb = Worksheets("清單明細").Cells(i, 3)

ActiveCell.Cells(, 4).Select
Exit For
End If
Next i
With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=" & bb
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With


End Sub

TOP

回復 5# GBKEE

請問G大
   會不會是因為我的陣列資料內有空值
而發生的錯誤

TOP

回復 8# GBKEE


    感謝G大的熱心
幫我解決難題

TOP

回復 8# GBKEE


    再請問G大一下
為何我的警告訊息不會出現


Sub 清單明細()

Dim bb, kk(30), aa
If ActiveCell.Cells.Column <> "4" Then Exit Sub

aa = ActiveCell
If aa = "Account Code " Then Exit Sub
If aa = "" Then Exit Sub
g = Worksheets("清單明細").Cells(65536, 2).End(xlUp).Row
For i = 1 To g
e = Worksheets("清單明細").Cells(i, 2)
If Worksheets("清單明細").Cells(i, 2) = aa Then

b = 0
j = Worksheets("清單明細").Cells(i, 34).End(xlToLeft).Column
    For a = 3 To j
        kk(b) = Worksheets("清單明細").Cells(i, a)
        b = b + 1
    Next a
bb = Join(kk, ",")
Exit For

End If
Next i
pp = Worksheets("清單明細").Cells(i, 3)
MsgBox pp, , "Account_Code說明"

ActiveCell.Cells(, 4).Select
ActiveCell = ""
With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:=bb
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = "You must enter a number from five to ten"
        .ShowInput = True
        .ShowError = True
    End With
Set kk(30) = Nothing
ActiveCell.Offset(, -5) = Date
ActiveCell.Offset(, 1) = Environ("UserName")
End Sub

TOP

本帖最後由 dafa 於 2012-1-17 08:29 編輯

回復 11# GBKEE

很抱歉說的不清楚
我測試Account Code欄位輸入錯誤資料時
為何出現警告訊息時沒有出現我輸入的字串  
.ErrorMessage = "You must enter a number from five to ten"


附件已上傳

2012-各業務負責人付款明細1.zip (388.96 KB)

TOP

回復 13# GBKEE


    感謝G大的解答
我又發現一個問題
就是陣列字元太多沒辦法全部塞入清單內
xlBetween, Formula1:=bb
有方法解決ㄇ?

TOP

回復 15# GBKEE


    感謝G大詳細的解釋
幫了我很大的忙
你真是好人
:D

TOP

        靜思自在 : 太陽光大、父母恩大、君子量大,小人氣大。
返回列表 上一主題