View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default .AddItem list and populating combobox with created list

I'm not sure how RowWorkMin gets declared and changed, but this worked ok for
me:

Option Explicit
Private Sub UserForm_Initialize()
Dim i As Long
Dim RowWorkMin As Long

RowWorkMin = 77

With Me.cboDirect
.RowSource = ""
.Style = fmStyleDropDownList
.MatchEntry = fmMatchEntryComplete
For i = RowWorkMin To 88
Me.cboDirect.AddItem i
Next i
End With

End Sub

If you want to allow the user to type an entry that isn't on the dropdown list,
you can change the .style to fmStyleDropDownCombo. (I'm kind of confused about
what you wanted.)


pallaver wrote:

Good afternoon -

Beginner macro user here having some serious trouble with creating
userforms.
Essentially I would to create a combobox which has a list from number
X to number Y.
In the case below, X is RowWorkMin (which is defined earlier without a
problem), and Y is set at 88.

The code below does not seem to be working.

Where am I going wrong? I have scoured the internet for hours for a
simple solution yet haven't found one, hence posting here. RowWorkMin
may change, but essentially it will be a list of integers in sequence,
i.e. ....13,14,15,16,.... etc.

The next step then which I will probably also need help with is how to
populate the combobox on my userform with this list.

Lastly, I've been reading that the combobox allows you to type in an
entry not present in the list. What if I'd like the option of having
the number I'd like to select typed in instead of selected by the drop
down menu of the combobox? Does this mean that I should make a text
box entry as well to accomodate for this selection/entry style?

Private Sub UserForm_Initialize()
Dim i As Integer

For i = RowWorkMin To 88
cboDirect.AddItem Str(i)
Next i

End Sub

Hopefully this makes sense. Thanks for any help in advance :) -
neil


--

Dave Peterson