Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Userform problem (Listindex)

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default Userform problem (Listindex)

Listindex starts with 0

See amended code:

HTH
--
AP

'-----------
Private Sub ComboBox1_Change()
Dim i As Long 'Index
i = ComboBox1.ListIndex + 1
Label1.Caption = Cells(i, 2).Value
Label2.Caption = Cells(i, 3).Value
Label3.Caption = Cells(i, 4).Value
CommandButton1.Enabled = i < ComboBox1.ListCount
CommandButton2.Enabled = i 1
End Sub

Private Sub CommandButton1_Click() 'Next Button
ComboBox1.ListIndex = ComboBox1.ListIndex + 1
Call ComboBox1_Change
End Sub

Private Sub CommandButton2_Click() 'Previous Button
ComboBox1.ListIndex = ComboBox1.ListIndex - 1
Call ComboBox1_Change
End Sub
'----------------------------------------------

"Gert-Jan" a écrit dans le message de
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Userform problem (Listindex)

This is GREAT!! Thanks a lot!

"Ardus Petus" schreef in bericht
...
Listindex starts with 0

See amended code:

HTH
--
AP

'-----------
Private Sub ComboBox1_Change()
Dim i As Long 'Index
i = ComboBox1.ListIndex + 1
Label1.Caption = Cells(i, 2).Value
Label2.Caption = Cells(i, 3).Value
Label3.Caption = Cells(i, 4).Value
CommandButton1.Enabled = i < ComboBox1.ListCount
CommandButton2.Enabled = i 1
End Sub

Private Sub CommandButton1_Click() 'Next Button
ComboBox1.ListIndex = ComboBox1.ListIndex + 1
Call ComboBox1_Change
End Sub

Private Sub CommandButton2_Click() 'Previous Button
ComboBox1.ListIndex = ComboBox1.ListIndex - 1
Call ComboBox1_Change
End Sub
'----------------------------------------------

"Gert-Jan" a écrit dans le message de
...
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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Userform problem (Listindex)

You have another reply at your other post.

Gert-Jan wrote:

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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform problem (Listindex) jgmiddel Excel Discussion (Misc queries) 1 April 26th 06 01:34 PM
Listindex strange problem Amit Shanker[_2_] Excel Programming 4 February 9th 05 06:53 PM
listbox listindex problem jacob Excel Programming 2 August 25th 04 08:46 AM
listindex Steph[_3_] Excel Programming 1 June 25th 04 06:14 PM
ListIndex Todd Huttenstine Excel Programming 2 May 13th 04 04:21 PM


All times are GMT +1. The time now is 11:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"