View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Combo box controlling visibility

dim cbox = MSForms.Combobox
should be
dim cbox as MSForms.Combobox

while I apologize for the typo, should you really be attempting this?

Anyway, I copied this form a working USERFORM

Private Sub combobox1_Click()
Dim cbox As MSForms.ComboBox
For Each ctrl In UserForm1.Controls
If TypeOf ctrl Is MSForms.ComboBox Then
Set cbox = ctrl
If Right(cbox.Name, 1) < 1 Then
cbox.Visible = False
End If
End If
Next
Controls("Combobox" & ComboBox1.ListIndex + 2).Visible = True
Me.Repaint
End Sub

Private Sub UserForm_Initialize()
Dim cbox As MSForms.ComboBox
For i = 1 To 5
For j = 1 To 4
Controls("ComboBox" & i).AddItem "Item " & j
Next
Next

For Each ctrl In UserForm1.Controls
If TypeOf ctrl Is MSForms.ComboBox Then
Set cbox = ctrl
If Right(cbox.Name, 1) < 1 Then
cbox.Visible = False
End If
End If
Next

End Sub

Tested in xl97, SR2

--
Regards,
Tom Ogilvy

Chris wrote in message
...
Hi there again. I pasted the code into the form's codes and I receive
an error. The error is that "dim cbox = MSForms.ComboBox" is a compile
error:Syntax error.



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