Hi there,
I currently found on this board a code to activate optionbuttons or checkboxes via the enter key on a userform.
This is done through a class module.
(The post I used)
I would like to do the same with the listboxes I have.
I have tried doing exactly the same as above but I don't understand the code so not sure how to modify it to work...
I suppose this has to do with the fact that Listboxes are not simple yes/no but depending on the listindex ...
If anyone can help I would be eternally grateful.
Mowgy
Class Module code (renamed properly):
Code in my userform
I currently found on this board a code to activate optionbuttons or checkboxes via the enter key on a userform.
This is done through a class module.
(The post I used)
I would like to do the same with the listboxes I have.
I have tried doing exactly the same as above but I don't understand the code so not sure how to modify it to work...
I suppose this has to do with the fact that Listboxes are not simple yes/no but depending on the listindex ...
If anyone can help I would be eternally grateful.
Mowgy
Class Module code (renamed properly):
Code:
Public WithEvents ListBoxGroup As MSForms.ListBox
Private Sub ListBoxGroup_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 13 Then Me.ListBoxGroup.Value = Not Me.ListBoxGroup.Value
End Sub
Code in my userform
Code:
Dim Lists() As New ListBoxClass
Code:
Private Sub UserForm_Initialize()
Dim Ctrl As Control
Dim Count As Integer
Dim Count2 As Integer
Dim Count3 As Integer
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "OptionButton" Then
Count = Count + 1
ReDim Preserve Buttons(1 To Count)
Set Buttons(Count).OptionButtonGroup = Ctrl
ElseIf TypeName(Ctrl) = "CheckBox" Then
Count2 = Count2 + 1
ReDim Preserve Boxes(1 To Count2)
Set Boxes(Count2).CheckBoxGroup = Ctrl
ElseIf TypeName(Ctrl) = "ListBox" Then
Count3 = Count3 + 1
ReDim Preserve Lists(1 To Count)
Set Lists(Count3).ListBoxGroup = Ctrl
End If
Next
End Sub