listbox items selection

PANKAJUTEKAR

Board Regular
Joined
Jun 10, 2011
Messages
79
Dear All,

i have taken listbox and there are two items in it.
mot
sfu

the folloowing is the code.
Private Sub Workbook_Open()
'ListBox1.Clear
ListBox1.AddItem "Motor"
ListBox1.AddItem "SFU"

The problem is-
Error 424 i got - object required.

i try some r&d, i think my excel sheet4 not able recognize this listbox1.

Can anyone give me the idea how to solve it?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Maybe like this if the listbox is on a sheet

Code:
Private Sub Workbook_Open()
'ListBox1.Clear
Sheets("Sheet1").ListBoxes("List Box 1").AddItem "Motor"
Sheets("Sheet1").ListBoxes("List Box 1").AddItem "SFU"
End Sub
 
Upvote 0
Assuming this a listbox from the activex control toolbox which is embedded onto your worksheet, the "object required" is your worksheet's name or codename.

This works, using your Sheet4 as a reference.


Code:
Private Sub Workbook_Open()
With Worksheets("Sheet4").ListBox1
.Clear
.AddItem "Motor"
.AddItem "SFU"
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top