Go Premium for a chance to win a PS4. Enter to Win


Excel VBA - open a DataValidation dropdown

Posted on 2016-11-22
Medium Priority
Last Modified: 2016-12-01
I have a cell which gets a DataValidation list when a button is clicked. See attached.

I'd like to make the List dropdown end up opened after the DataValidation is created in the cell. I understand it requires 'Send Keys'. Can someone please show me how it's done?

Question by:hindersaliva
  • 3
  • 2
LVL 34

Assisted Solution

by:Rob Henson
Rob Henson earned 1000 total points
ID: 41897738
The keyboard shortcut for opening a dropdown is Alt + Down arrow.

SendKeys ("%{Down}")

Author Comment

ID: 41897788
When I do this nothing happens (having disabled the Worksheet_Change in the example)

Sub FillTheDropdown()
    With Selection.Validation
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="Tom, Dick, Harry"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    'open the InCellDropdown
        Application.SendKeys ("%{DOWN}")

End Sub

Open in new window

Shouldn't that fill the InCell DataValidation list AND leave it 'Open'?
LVL 34

Expert Comment

by:Rob Henson
ID: 41897793
Just that script on its own works for me, I guess it must be something to do with the fact that you have disabled Worksheet_Change event.

Try adding

Open in new window

in a line before the SendKeys
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 41897805
Does this work for you?
LVL 23

Accepted Solution

Ejgil Hedegaard earned 1000 total points
ID: 41898138
DoEvents is not needed, but use the Selection_Change event, instead of the Change event
Then select the cell and the list is shown.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target = Range("H16") Then
    End If
End Sub

Open in new window


Author Comment

ID: 41909030
I think my problem was, the code was in a Module instead of the Sheet Module.
I have since decided not to use SendKeys as it is known to be unreliable.

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question