Manually Update Listindex

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a combobox on a user form that is populated when the form opens. The
listindex is not updated unless I "reselect" the same value from the dropdown
menu. How can I have the listindex automatically update when the combobox is
populated. This is on a pretty new version of Excel for Mac. I don't have
this problem with the older version of Excel for Mac.

Thanks for any help

DB
 
Hello DB,

What OS are you running? I tested setting the Listindex of ComboBox
using Excel with OS X . I placed the code in the User Form Initialize
Event module with no problems. I used ComboBox1.ListIndex = 3 to bring
up the 4th item in my list of 5 with no problems. Maybe you should post
your code.

Sincerely,
Leith Ross
 
Can't you just set the listindex at the end of your population code.

Something like

Private Sub UserForm_Initialize()
Dim lCounter As Long
With cbInput
Application.EnableEvents = False
For lCounter = 1 To 10
.AddItem lCounter
Next lCounter
Application.EnableEvents = True
.ListIndex = 0
End With
End Sub

Robin Hammond
www.enhanceddatasystems.com
 
Leith Ross said:
Hello DB,

What OS are you running? I tested setting the Listindex of ComboBox
using Excel with OS X . I placed the code in the User Form Initialize
Event module with no problems. I used ComboBox1.ListIndex = 3 to bring
up the 4th item in my list of 5 with no problems. Maybe you should post
your code.

Sincerely,
Leith Ross
 
Basically, the combobox2 list depends on the value of combobox1. If I select
a value from the combobox1 list, combobox2 works just fine. However, if the
value of combobox1 is set by code (see below) to a value that is the same as
one in the list for combobox1, the list index does not change accordingly. I
just had a thought: do you think I need to change the order of the two lines
of code in the Initialize sub?

Private Sub UserForm_Initialize()
ComboBox1.Value = Sheets("Sheet1").Cells(4, 3).Value
ComboBox1.List = Sheets("Sheet2").Range("B5:B10").Value
End Sub
Private Sub ComboBox2_Enter()
Dim ListRow As Long
ListRow = ComboBox1.ListIndex + 5
ComboBox2.AddItem (Sheets("Sheet2").Cells(ListRow, 3).Value)
End Sub
 
Back
Top