J
jgmiddel
In A1 - D20 I have values. The range A1 - A20 is the input for the
ComboBox
in my userform. What should happen is the following: ComboBox ->
onchange:
refresh the data in the labels. If the selected item in the ComboBox is
the
value from A10, in Label 1 should the value of B10 appear, etc. And: if
the
first item is selected, the PREVIOUS button must be disabled, when the
last
item is selected, the NEXT button.
I have some errors in the code:
- when the first item is selected, I get an error
- when the second item is selected, the button NEXT is disabled
- when the last item is selected, the button NEXT is still enabled,
pressing
it will lead to an error
I think there are some errors in the lines "i = ComboBox1.ListIndex". I
made
some changes, but they didn't work properly. Any suggestions??
--------
Private Sub ComboBox1_Change()
Dim i As Long 'Index
i = ComboBox1.ListIndex
If i = ComboBox1.ListCount Or i = 1 Then CommandButton1.Enabled =
False
Label1.Caption = Cells(i, 2).Value
Label2.Caption = Cells(i, 3).Value
Label3.Caption = Cells(i, 4).Value
End Sub
Private Sub CommandButton1_Click() 'Next Button
Dim i As Long
i = ComboBox1.ListIndex
If i < ComboBox1.ListCount Then
ComboBox1.ListIndex = i + 1
If i + 1 = ComboBox1.ListCount Then CommandButton1.Enabled = False
Else
CommandButton1.Enabled = False
End If
End Sub
Private Sub CommandButton2_Click() 'Previous Button
Dim i As Long
i = ComboBox1.ListIndex
If i > 1 Then
ComboBox1.ListIndex = i - 1
If i - 1 = 1 Then CommandButton2.Enabled = False
Else
CommandButton2.Enabled = False
End If
End Sub
ComboBox
in my userform. What should happen is the following: ComboBox ->
onchange:
refresh the data in the labels. If the selected item in the ComboBox is
the
value from A10, in Label 1 should the value of B10 appear, etc. And: if
the
first item is selected, the PREVIOUS button must be disabled, when the
last
item is selected, the NEXT button.
I have some errors in the code:
- when the first item is selected, I get an error
- when the second item is selected, the button NEXT is disabled
- when the last item is selected, the button NEXT is still enabled,
pressing
it will lead to an error
I think there are some errors in the lines "i = ComboBox1.ListIndex". I
made
some changes, but they didn't work properly. Any suggestions??
--------
Private Sub ComboBox1_Change()
Dim i As Long 'Index
i = ComboBox1.ListIndex
If i = ComboBox1.ListCount Or i = 1 Then CommandButton1.Enabled =
False
Label1.Caption = Cells(i, 2).Value
Label2.Caption = Cells(i, 3).Value
Label3.Caption = Cells(i, 4).Value
End Sub
Private Sub CommandButton1_Click() 'Next Button
Dim i As Long
i = ComboBox1.ListIndex
If i < ComboBox1.ListCount Then
ComboBox1.ListIndex = i + 1
If i + 1 = ComboBox1.ListCount Then CommandButton1.Enabled = False
Else
CommandButton1.Enabled = False
End If
End Sub
Private Sub CommandButton2_Click() 'Previous Button
Dim i As Long
i = ComboBox1.ListIndex
If i > 1 Then
ComboBox1.ListIndex = i - 1
If i - 1 = 1 Then CommandButton2.Enabled = False
Else
CommandButton2.Enabled = False
End If
End Sub