'Why this error `Run-time :Application-defined or object-defined error` although using If (InCellDropdown = True)
I am using below code to automatically open Dropdown List.
In my test range I intentionally left some cells without any data validation,
I thought the event will not be firing (on cells without data validation) after I used this line If Target.Validation.InCellDropdown = True Then
But I got that error
Run-time error '1004':Application-defined or object-defined error
Is this if condition useless ? thanks for any learning assistance
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("H:H")) Is Nothing And _
Target.Cells.CountLarge = 1 And Target.Row > 1 Then
If Target.Validation.InCellDropdown = True Then
Application.SendKeys ("%{DOWN}")
End If
End If
End Sub
Solution 1:[1]
It's not exactly useless, it's just a thing VBA does: if the target has no validation, it brings up your error, because cells, that have validation are treated as SpecialCells, not as regular Cells, if that makes sense. Anyway, to make your code work, you can try:
On Error Resume Next
If Target.Validation.InCellDropdown = True Then
Application.SendKeys ("%{DOWN}")
End If
On Error GoTo 0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PirateNinja |
