2015-05-18 18 views

回答

1

這是一種方法。這將檢查工作表中的任何單元格是否具有驗證。如果它不存在,則退出該子。如果有,則檢查當前電池是否是那些驗證電池的一部分

Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
    Dim r As Range 

    Application.EnableEvents = False 

    On Error Resume Next 
    Set r = Cells.SpecialCells(xlCellTypeAllValidation) 
    On Error GoTo 0 

    If Not r Is Nothing Then 
     On Error GoTo Whoa 

     If Not Intersect(Target, r) Is Nothing Then 
      If Target.Validation.Type = 3 Then 
       ' 
       '~~> Your code 
       ' 
      End If 
     End If 
    End If 

Letscontinue: 
    Application.EnableEvents = True 
    Exit Sub 
Whoa: 
    MsgBox Err.Description 
    Resume Letscontinue 
End Sub 
相關問題