View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
bob cochran bob cochran is offline
external usenet poster
 
Posts: 7
Default adding items to combobox using "Tag" control to limit

The following was submitted to me from another post. (Thanks Dick) The
only changes I made were changing "UserForm_Initialize" to
"frmMaintest_Initialize".

The items are not showing in the combobox(s). Do I still need to
include a reference in the Row Source of the ComboBox(s)? I am using XP
and think this could be to blame. Can someone take a look and see if
something is missing?

I want to use the same list, but limit which combobox(s) show which
items.

Thanks in advance!
Bob C.

Sheet1.Range("a1:a3") contains

Card1
Card2
Card3

Userform1 has three comboboxes with Tag properties of

Card1;Card2
Card2;Card3
All

respectively. In the initialize event of the form, I populate the
comboboxes based on their Tags

Private Sub UserForm_Initialize()

Dim CardRng As Range
Dim Cell As Range
Dim Ctl As Control
Dim AllowedCards As Variant
Dim i As Long

Set CardRng = Sheet1.Range("a1:A3")

For Each Ctl In Me.Controls
If TypeName(Ctl) = "ComboBox" Then
If Len(Ctl.Tag) 0 Then
If Ctl.Tag = "All" Then
For Each Cell In CardRng.Cells
Ctl.AddItem Cell.Value
Next Cell
Else
AllowedCards = Split(Ctl.Tag, ";")
For Each Cell In CardRng.Cells
For i = LBound(AllowedCards) To _
UBound(AllowedCards)

If Cell.Value = AllowedCards(i) Then
Ctl.AddItem Cell.Value
End If
Next i
Next Cell
End If
End If
End If
Next Ctl

End Sub



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!