View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Selected item in combobox at DropButtonClick

If I follow, this worked for me

Private Sub UserForm_Click()
Dim nIdx As Long
Dim arrYears(1 To 111)
For i = 1 To 111
arrYears(i) = Year(Date) - (101 - i)
Next i
nIdx = 100
With ComboBox1
.List = arrYears
.ListIndex = IIf(nIdx - 4 0, nIdx - 4, 0)
.ListWidth = 48
.ColumnWidths = 48
.DropDown
.ListIndex = nIdx
End With
End Sub

Regards,
Peter T

"RB Smissaert" wrote in message
...
On a userform I have a combobox with a number of integer numbers that are
years.
On DropButtonClick I would like to have a certain item (the current year)
selected and
have that item at about the middle (height-wise) of the combobox.
The combobox is populated like this:

For i = 1 To 111
arrYears(i) = Year(Date) - (101 - i)
Next i

With ComboBox1
.List = arrYears
.ListIndex = 100
.ListWidth = 48
.ColumnWidths = 48
End With

How could I do this without using SendKeys or the Windows API?


RBS