On focus after tabbing of Excel drop down, automatically show list for selection

前端 未结 2 391
我在风中等你
我在风中等你 2020-12-12 01:37

I have some data validation drop down lists in excel, I can tab through all the lists but I have to press alt + down arrow to show the list, Is their a way it can be automat

相关标签:
2条回答
  • 2020-12-12 02:22

    I found this helpful but would like to pass on a couple of observations.

    1. Using

      If Target.Cells.Count = 1 Then

      If Target.Validation.InCellDropdown = True Then

    in the event will apply this to all validation drop lists on the sheet rather than listing the individual cells. You need the first if to avoid an error caused by selecting multiple cells.

    1. Beware of send keys being called twice in a row. It turns your num lock off and I had to add an API call to turn it back on again.

    I hope this helps others

    0 讨论(0)
  • 2020-12-12 02:27

    edit: still using VBA send keys.

    On the sheet where the data validation cell resides (assumed it is cells A1:C1 on Sheet1), put in the following code in the Microsoft Excel Sheet1 Module (the module that holds the VBA code that is related to the first sheet)

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        On Error GoTo Err1:
    
        If Target = Range("A1") Then
            Application.SendKeys ("%{UP}")
        End If
    
        If Target = Range("B1") Then
            Application.SendKeys ("%{UP}")
        End If
    
        If Target = Range("C1") Then
            Application.SendKeys ("%{UP}")
        End If
    
    Err1:
        'do nothing
    End Sub
    
    0 讨论(0)
提交回复
热议问题