Excel VBA - InCell Dropdown - open with VBA

I have this. When I double-click a cell an InCell Dropdown is created. That works fine.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Call AddInCellDropdown
    
End Sub

Open in new window


and

Sub AddInCellDropdown()

    Dim str As String
    Dim rst As ADODB.Recordset

    str = "one, two, three" 'list of dropdown items
    
    'put in cell
    With Selection.Validation
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, _
             Formula1:=str
        .IgnoreBlank = True
        .InCellDropdown = True
    End With

End Sub

Open in new window


That works fine. But the cell is selected in 'edit mode', because of the double-click I guess.

I'd like it ...
1. to come out of the edit mode, like hitting Esc. (in causes an error also when I select an item from the dropdown). Tried recording a macro but no code is written.
AND
2. to open the dropdown. ie. to leave the dropdown open.

Thanks!
hindersalivaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

[ fanpages ]IT Services ConsultantCommented:
Hi,

Do you see the same issue(s) with this additional statement?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Call AddInCellDropdown
    
    Cancel = True ' *** Add this line

End Sub

Open in new window


Tackling your two points may mean a different approach; I just wish to see if I understand your requirements completely.
0
hindersalivaAuthor Commented:
Fanpages, that works perfectly! Thanks!

now for the second part ....
0
[ fanpages ]IT Services ConsultantCommented:
OK.  Thanks.

Part 2 (I think)

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Call AddInCellDropdown
    
    SendKeys "%{Down}" ' *** Part 2
    
    Cancel = True ' *** Part 1
    
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

[ fanpages ]IT Services ConsultantCommented:
PS. Also a suggestion to stop a potential run-time error...

Sub AddInCellDropdown()

    Dim str As String
    'Dim rst As ADODB.Recordset                         ' *** Removed as not required in this cut-down version

    str = "one, two, three" 'list of dropdown items
    
    Selection.Validation.Delete                         ' *** Suggested additional statement
    
    'put in cell
    With Selection.Validation
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, _
             Formula1:=str
        .IgnoreBlank = True
        .InCellDropdown = True
    End With

End Sub

Open in new window

2
hindersalivaAuthor Commented:
Works perfectly! Man, you're a genius!
THANKS!
1
[ fanpages ]IT Services ConsultantCommented:
No problem at all.

If you wish to read-up on "SendKeys", here is a suitable source of information:

[ https://msdn.microsoft.com/en-us/library/office/gg278655%28v=office.15%29.aspx ]
2
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
+1 from me too. :)
0
[ fanpages ]IT Services ConsultantCommented:
Thanks sktneer :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.