1
我想,以確定如果單元格使用此語句數據驗證:Target.Validation.Type結果「應用程序定義或對象定義的」錯誤
If Target.Validation.Type = 3 Then
不過,我得到的VBA錯誤:
應用程序定義或對象定義的錯誤
我嘗試使用On error Resume Next
和On error Goto 0
,但它並不能幫助。
如何檢查單元是否包含數據驗證?
我想,以確定如果單元格使用此語句數據驗證:Target.Validation.Type結果「應用程序定義或對象定義的」錯誤
If Target.Validation.Type = 3 Then
不過,我得到的VBA錯誤:
應用程序定義或對象定義的錯誤
我嘗試使用On error Resume Next
和On error Goto 0
,但它並不能幫助。
如何檢查單元是否包含數據驗證?
這是一種方法。這將檢查工作表中的任何單元格是否具有驗證。如果它不存在,則退出該子。如果有,則檢查當前電池是否是那些驗證電池的一部分
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