Is there any alternative toSendKeys
to expand drop-down validation list automatically? I would like to expand drop-down validation list after clicking on a cell. The focus of my question is entirely on how to avoid SendKeys
method.
Here is a properly working solution using SendKeys
:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If HasValidation(Target) Then
SendKeys "%{DOWN}"
SendKeys "{NUMLOCK}", True 'Workaround for Numlock turn off bug
End If
End Sub
Function HasValidation(MyCell As Range) As Boolean
Dim t: t = Null
On Error Resume Next
t = MyCell.Validation.Type
On Error GoTo 0
HasValidation = Not IsNull(t)
End Function
Related links:
HasValidation
function: https://stackoverflow.com/a/31346246/1903793
NumLock
bug: https://stackoverflow.com/a/29551913/1903793
The code above works smoothly without a hitch. I am just biased againstSendKeys
for widely reported issues. I suspect that incorporating this solution into larger code might cause unexpected behavior in the future which might be hard to capture.