preselect listbox item

greg kramer

New Member
Joined
Dec 13, 2009
Messages
24
I know that you can select an item or preselect an item with the following syntax:

listbox.selected(1) = true

but how would one convert the 1 to text from another source so that it would work the same way

that is,

listbox.selected("word")=true

probably not formulating the question very well but any thoughts would be appreciated.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
It the value matches an item in the list and the listbox is not multiselect then you should be able to do this.
Code:
Listbox1.Value = "Word"
If it's not on the list or the listbox is multiselect then you'll get an error, something like 'Invalid property value'.
 
Upvote 0
What are you trying to do? Where are the values you want to reject coming from?
 
Upvote 0
Rasm\Norie-

Thanks for responding.

The list box is populated from a listfillrange on another sheet.

In a sperate area, there is a default value for this list in a cell that I would like to use to preselect it in the multiselect listbox.

Guess we can't post screen shots on the board...shame, picture is worth 1000k words.

Regards,

Greg
 
Upvote 0
you can add items to your list


ListBox1.additem "YourCellValue"

to clear the lsitbox use ListBox1.clear

I assume this is an activeX control

If you want to trigger an event when you click that cell then use this in ThisWorkBook

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

End Sub

The Target.Address will give you the coordiantes of the cell clicked - or use Target.Row or Target.Column - all depends on your needs.

Not sure if this helps
 
Upvote 0
Thanks Rasm but I'm trying to select an item not add it.

This list is already fully populated.

When the users select the page they would have a default value highlighted in blue, somehow.

Which is why I was thinking it would be along the lines of:

listbox.selected(default value)=true
 
Upvote 0
You have to refernc eit with an index - then they will be blue and selected.



i.e.
listbox.selected(0)=true
listbox.selected(4)=true


so do a loop

for i=0 to listbox1.listcount-1
if Listbox1.list(i) = "NameOfYourString" then ListBox1.selected(i)=True

next i


So something like that
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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