Select a value in targeted Listbox

atf32

Board Regular
Joined
Apr 13, 2011
Messages
157
Looking for a way (code) that will make the selected value of a targetted listbox (say listbox1) it's first value in the Listbox1.:confused:

EXAMPLE:
1 ) items in listbox1 are:
- Apple
- Orange
- Banana
- Cherry

2) Value is FALSE and the selected values in listbox1 are crrently
"Banana" and "Cherry".
3) Value is now TRUE
4) Since value is TRUE, the selectedvalue for listbox1 should default to
the first value of the list ("Apple").:confused:
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
What is VALUE?

If all you want to do is select the first item in a multiselect listbox you can use this.
Code:
ListBox1.Selected(0) = True
If you need all other items deselected:
Code:
For I = 0 To Listbox1.ListCount-1
       Listbox1.Selected(I) =False
Next I
 
Listbox1.Selected(0) = True
 
Upvote 0
Thanks....I originally tried your first example, but it did not work (why I originally posted question). I'll try again. Thanks for the quick response.
 
Upvote 0
Ok, it turns out this needs a little more thought........I have two listboxes (on the surface of excel, not on a form). The first value in each listbox is the value "ALL". The rest are various list of items. I have it set up so that if I were to select a value in listbox1, the code will also default the selected value in listbox2 to "ALL" (the first value). This is also set up to work vice versa, should I select a value in listbox2. My problem now is that I created a loop since both listboxes are set on "Change". I want this to be an immediate change, so I'm trying to stay away from using the "lostfocus". I tried to use "Click", but the code will not run. ...Any suggestions? :confused:
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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