Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble setting object variables to form controls

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
Excel 2007. I'm having trouble setting some objects to form controls on my worksheet. Some object classes will bind, such as the combo box, but others won't. I keep getting a Type Mismatch error and I'm not sure why. See below:

[red]Run-time error '13':
Type mismatch[/red]


Code:
    Dim cboTest     As ComboBox
    Dim lstList     As ListBox
    Dim wksRefSheet As Worksheet
    
    Set wksRefSheet = Worksheets("Chemical Data")
    Set cboTest = Worksheets("sheet2").cboTestCombo
    [highlight]Set lstList = Worksheets("sheet2").lstChemicals[/highlight]

The code runs smoothly until I set the listbox class. But the combo box binds just fine. Other controls, such as textboxes and option buttons wont bind either. The names are correct. The problem occurs wether I'm working with form controls in a form module, or worksheet controls from within worksheet module. Why will this not work?

-JTBorton
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 
What about this ?
Dim lstList As MSForms.ListBox

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top