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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListFillRange

Status
Not open for further replies.

WelshyWizard

IS-IT--Management
Apr 23, 2006
89
GB
I'm new to this so please bare with me...

In Excel I'm trying to fill a listbox on sheet1 with a range of data on sheet2.
I try to do this with the dode below:

Code:
Sheet1.ListBox1.ControlFormat.ListFillRange = "Sheet2!A5:B11"

However, when I run this I get the following error:
'Object Required'

I'm a bit confused by this... I've set the column count of the listbox to 2 and I've also managed to link to the selected field through the list boxes properties.... What am I doing wrong?!

If I get this working I'm planning upon changing the range for a variable range that will be different everytime, but 1st things 1st!

Thanks.
 
Perhaps this ?
ActiveWorkbook.Sheets("Sheet1").ListBox1.ControlFormat.ListFillRange = "Sheet2!A5:B11"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hmm, probably hit submit too fast.
I guess you have to play with the Shapes collection ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PH,

Unfortunatley I now get:
'Object doesn't support this property or method'

Any other ideas? I've tried loads of variations and looked on loads of sites but just can't get it to work!

Today is the tomorrow you worried about yesterday - and all is well.....
 
ComboBox1.ListFillRange = Sheets("Sheet2").Range("A1:A4").AddressLocal(External:=True)
 
Sheet1 is the code name. That error message means Excel cannot find the object you specified (with a code name of ListBox1) within that sheet. Ensure you are using the correct name on the correct sheet.

-----------
Regards,
Zack Barresse
 
Ok..... I can get this code to work... However, I can't seem to get into the properties to change the columncount to 2 so it is only showing the 1st column.... Any ideas how to do this using code? I know there is a columncount command but this only seems to be for forms?

Cheers.

Today is the tomorrow you worried about yesterday - and all is well.....
 
Sorry! I forgot to actually add the code into my post!

Code:
With Worksheets(1)

        Set lb = .Shapes.AddFormControl(xlListBox, 10, 10, 200, 100) 
        lb.ControlFormat.ListFillRange = "Sheet2!A5:B11"
      
End With

Today is the tomorrow you worried about yesterday - and all is well.....
 
I used the .additems command in the end... Worked a treat!

Thanks for all of your help.

Today is the tomorrow you worried about yesterday - and all is well.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top