Combobox Value

N

Nate Kolman

I'm fairly new to VBA, but learning fast! Okay, so here's the
problem...

I've got Form1 with 2 optionbuttons, 2 comboboxes, and a
commandbutton. The optionbuttons tell what list will show in the
comboboxes, then the value chosen in the combobox will filter the main
data when the commandbutton is clicked. I'm having problems getting
the value of the comboboxes to show up, so I broke it down as simple
as I could.

Dim CVal As Variant

CVal = Form1.CptyBox.Value
MsgBox CVal

What I'm getting is a blank message box to appear (it should have a
value in it). Am I not referring to the combobox properly? Any ideas
are appreciated.

Thanks.
 
P

Patrick Molloy

on a userform it should work...
drop two option buttons, one con=mbobox and a command
button onto a new userform, leave the names with the
default. add the following code

Private Sub CommandButton1_Click()
MsgBox UserForm1.ComboBox1.Value
End Sub

Private Sub OptionButton1_Click()
With ComboBox1
.Clear
.AddItem "A"
.AddItem "B"
End With
End Sub

Private Sub OptionButton2_Click()
With ComboBox1
.Clear
.AddItem "X"
.AddItem "Y"
End With
End Sub



hth
Patrick Molloy
Microsoft Excel MVP
 
Top