View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
Gert-Jan Gert-Jan is offline
external usenet poster
 
Posts: 49
Default Userform for displaying values from a row

Hi,

Thanks a lot for helping! The labels are getting filled now, but there are
some errors:

- after opening the userform: when I select the first item: I get an error
from VBA.
- when the second item is selected; the button "next" is disabled.
- when the last item is selected, the "next" button is still enabled

This is what I got till now:

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
'etc
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


"Die_Another_Day" schreef in bericht
ups.com...
Here is an easier to read version:

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
Label4.Caption = Cells(i, 5).Value
Label5.Caption = Cells(i, 6).Value
Label6.Caption = Cells(i, 7).Value
End Sub

Let me know if that gets the job done

Die_Another_Day