Forum Discussion
Trismos
Dec 05, 2019Copper Contributor
Using conditional formatting or VBA to automatically open the next drop down menu after selecting ?
I am trying to streamline a report format to make it more usable: it has a list of questions followed by a drop down menu - example attached. After selecting an item in the current drop down I would ...
- Dec 05, 2019
Subodh_Tiwari_sktneer
Dec 05, 2019Silver Contributor
You may place the following code on Sheet Module to see if this is what you are trying to achieve.
e.g. if you select an answer from the dropdown list in AM4, the dropdown list in AM5 will expand automatically for you to choose an answer.
Code on Sheet Module:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Variant
On Error Resume Next
n = Target.Validation.Type
On Error GoTo 0
If n = 3 Then
n = 0
On Error Resume Next
n = Target.Offset(1, 0).Validation.Type
On Error GoTo 0
If n = 3 Then
Target.Offset(1, 0).Select
SendKeys "%{Down}"
End If
NUM_On
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
NUM_On
End Sub
Code on a Standard Module like Module1:
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Const VK_NUMLOCK = &H90
Private Const KEYEVENTF_KEYUP = &H2
Declare Function GetKeyState Lib "user32.dll" ( _
ByVal nVirtKey As Long) As Integer
Sub NUM_On()
If Not (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
End Sub
SendKeys method may mess up with the Numlock. Though I have tried to handle that, it is inconsistent to work the same way. See if this is something you can work with.
Trismos
Dec 05, 2019Copper Contributor