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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows
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'.
 

Rasm

Well-known Member
Joined
Feb 9, 2011
Messages
500
Astr=Listbox1.list(i) - this gives you the text - is that your question?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

What are you trying to do? Where are the values you want to reject coming from?
 

greg kramer

New Member
Joined
Dec 13, 2009
Messages
24
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
 

Rasm

Well-known Member
Joined
Feb 9, 2011
Messages
500

ADVERTISEMENT

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
 

greg kramer

New Member
Joined
Dec 13, 2009
Messages
24
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
 

Rasm

Well-known Member
Joined
Feb 9, 2011
Messages
500
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
 

greg kramer

New Member
Joined
Dec 13, 2009
Messages
24
Yes!

That's it.

Rasm, I owe you. Will send you a starbucks cards or something...please let me know.

Regards,

Greg
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,486
Messages
5,831,968
Members
430,098
Latest member
bemmelen

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
Top