Board logo

標題: 再問資料驗證 [打印本頁]

作者: modelcrazyer    時間: 2012-10-15 23:49     標題: 有關資料驗證的問題

附件是我的表單和程式,想請教各位達人
我該怎麼修改才能讓我的A列中的數字
不會因為我的滑鼠到處亂點,而一直增加上去
作者: GBKEE    時間: 2012-10-16 07:39

回復 1# modelcrazyer
不會因為我的滑鼠到處亂點,而一直增加上去
那你希望在何條件下執行  Sub Worksheet_SelectionChange
作者: modelcrazyer    時間: 2012-10-16 22:03

謝謝!!我已經解決了!!
作者: modelcrazyer    時間: 2012-10-19 00:24     標題: 再問資料驗證

各位達人:
以下是我的資料驗證程式
S = Worksheets("工作表2").Cells(Rows.Count, "a").End(xlUp).Row
Num3 = Worksheets("工作表1").Cells(Rows.Count, "a").End(xlUp).Row
With Worksheets("工作表2").Range("A" & S + 1).Validation
   .Delete
   .Add Type:=xlValidateList, Operator:= _
    xlBetween, Formula1:="=工作表1!$A$2:$A$" & Num3
    .IgnoreBlank = Fsale
     .InCellDropdown = True
    .ShowInput = True
    .ShowError = True
End With
我有個天馬行空的想法不知道能不能辦到,就是當我點選了某個A欄的資料驗證後
該儲存格就不會出現下拉選單,但是當我用delete把該儲存格的資料清除後
又能再出現資料驗證的下拉選單,這樣的想法有沒有可能辦到
作者: GBKEE    時間: 2012-10-19 08:10

回復 4# modelcrazyer
這工作表的程式碼
  1. Option Explicit
  2. Private Sub Worksheet_Change(ByVal Target As Range)
  3.     Ex Target(1)
  4. End Sub
  5. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  6.     Ex Target(1)
  7. End Sub
  8. Sub Ex(xlTarget As Range)
  9.     On Error Resume Next
  10.     '設定當一個執行階段錯誤產生時,程式控制立刻到發生錯誤陳述式接下去的陳述式,而繼續執行下去
  11.     If xlTarget.Column = 1 Then   'A欄
  12.         With xlTarget
  13.             If .Value <> "" Then
  14.                 .Validation.InCellDropdown = False  '沒有資料驗證會有錯誤
  15.             Else
  16.                 .Validation.InCellDropdown = True   '沒有資料驗證會有錯誤
  17.             End If
  18.         End With
  19.     End If
  20. End Sub
複製代碼





歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)