I’m trying to set up a forms list box control with the selection type set to “Extend”. It works great except I can’t figure out how to retrieve the items that are selected!! When it was set to “single” the index number of the value goes to the cell specified in Cell Link. I read something in the Microsoft Knowledge Base that the only way to retrieve the selected items when the type is “Multi” or “Extend” is with VBA code. Ok, but I can’t find any examples of how to do this. I be happy if I could just get a list of the index numbers of the selections in a cell or a range of cells similar to the way the index to the selected item gets put into the cell link if the selection type is “Single”. Can anybody help me please????
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Extend Selection of Listbox (Excel 98 thru 2002)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Extend Selection of Listbox (Excel 98 thru 2002)
- This topic has 20 replies, 6 voices, and was last updated 22 years, 7 months ago.
Viewing 1 reply threadAuthorReplies-
WSAndrew Cronnolly
AskWoody LoungerJune 25, 2002 at 7:46 pm #596970The following loops through all items (the first has an index value of 0) in a listbox and prints the items that are select to the immediate wind :
For i = 0 To (ListBox1.ListCount) - 1 If ListBox1.Selected(i) = True Then Debug.Print "Item " & i & " selected" End If Next
If the item is selected the selected property = True, otherwise False.
Andrew C
-
WSStymied
AskWoody LoungerJune 25, 2002 at 8:20 pm #596987Sounds promising, thanks to both of you for the input, but I’m having trouble getting past the name of the listbox. I went to “Assign Macro” on the menu and it gave me the name of the default macro (in this case ListBox27_Change()) so I assumed the listbox name would be listbox27. So I added code to the macro “If ListBox27.Selected(0) = true then…” but when I click on an item in the list I get a pop up window with “Run-Time Error ‘424’ Object Required” and the de###### puts the yellow highlight on the line with my if statement. What am I doing wrong?
Thanks -
WSAndrew Cronnolly
AskWoody LoungerJune 25, 2002 at 10:59 pm #597020It seems you are using a Listbox from the Forms Toolbar, rather than the Control tools. The example I offered was based on the assumption you were using a Listbox on a UserForm. However if you use a listbox from the Control toolbox, the samr approach applies. However the best place for the code is in the Workshhet codepane. To access that right click on the sheet tab and select View code. See the attached graphic. The example included uses the LostFocus event fill a range of cells to indicate the state of each item.
You can select different events to code for from the right hand side dropdown of the codepane.
Andrew C
-
WSStymied
AskWoody LoungerJune 26, 2002 at 3:48 pm #597221GLUB, GLUB, GLUB… I think I’m in WAY over my head!!!!
I was hoping for a much simpler solution. You are delving into areas about which I know nothing… yet. I do appreciate the help but I’m afraid I’m too far behind to catch up. I can’t even figure out how to assign the input range to the control list box the way I did for the forms listbox. The Format Control menu option window does not have a Control tab like the Forms List Box does. I see where the code goes that you mentioned and it seems to think this control is ListBox1. Is there an easier way out??
Thanks -
WSDoryO
AskWoody Lounger -
WSStymied
AskWoody LoungerJune 26, 2002 at 6:30 pm #597264A Grand Idea, Sister! In fact, in my struggles over all this I’ve thought of a couple of different ways to accomplish my goal, the sad fact is I have a large workbook with many formulas based on two form listboxes that work fine when the selection type is set to single. I am trying to expand the functionality of this complex workbook without changing the way it looks to the people using it and without changing any more than I have to!
Generally, I have a list with several columns of data one of which contains a reference number to another list. The other list is a numbered list with two columns. I then use this data to choose rows from the first list according to data in one column via a listbox. I then further limit the selected rows by selecting from the included reference numbers in the second listbox.
I’ve attached a print screen image of a simplified example.
In this example the first listbox shows a sorted list of unique automobile models. When an item is chosen from the first listbox the second listbox is populated with a sorted list of unique color combinations taken from the first list. When an item is chosen from this list a line is generated that displays a sentence using the selected data. I would like to expand this to allow choosing two or more color references and then generate two or more sentences.
I hope this is general enough. I do hope someone can help. If I could just figure out how to retrieve the selections from the pesky form listbox I’d be able to work out the rest.
Thanks -
WSAndrew Cronnolly
AskWoody LoungerJune 26, 2002 at 6:29 pm #597262If you want to use a Listbox from the Forms toolbar, try smething like the following. It uses a Listbox called Listing which has a predefined Input Range. Assign the following code to a button, which when clicked will fill a range starting at A1 with all selected items. A demo workbook is attached.
Sub GetListSelections() Dim Listing1 As ListBox Dim ListArray As Variant Dim Item As Long, i As Long [A:A].ClearContents Set Listing1 = ActiveSheet.ListBoxes("Listing") ListArray = Listing1.Selected For i = 1 To UBound(ListArray) If ListArray(i) = True Then [A1].Offset(Item, 0) = Listing1.List(i) Item = Item + 1 End If Next End Sub
Hope it gets you started.
Andrew C
-
WSStymied
AskWoody Lounger -
WSAndrew Cronnolly
AskWoody LoungerJune 26, 2002 at 7:51 pm #597285It will work wihot the button, bur be aware that the code runs each time any one item in the listbox is selected. However if you are feeling adventurous, you can adapt it slightly and apply the same code to 2 different listboxes. On the attached sample I have set a different LinkedCell for both listboxes and assigned the following code to both :
Sub GetListSelections() Dim Listing1 As ListBox Dim ListArray As Variant Dim Item As Long, i As Long Dim oCell As Range Set Listing1 = ActiveSheet.ListBoxes(Application.Caller) Set oCell = Range(Listing1.LinkedCell) ListArray = Listing1.Selected Range(oCell, oCell.End(xlDown)).ClearContents For i = 1 To UBound(ListArray) If ListArray(i) = True Then oCell.Offset(Item, 0) = Listing1.List(i) Item = Item + 1 End If Next End Sub
Something to experiment with.
Andrew C
-
WSStymied
AskWoody Lounger -
WSStymied
AskWoody Lounger -
WSAndrew Cronnolly
AskWoody Lounger
-
-
WSjstevens
AskWoody LoungerNovember 12, 2002 at 12:03 am #630948Andrew,
This was a good exercise. I understand the User Form version but when I try to apply the ListBox from the Custom Toolbar I have difficulty transitioning Set Listing1 = ActiveSheet.ListBoxes(“Listing”). The range “Listing” can not be assigned to the ToolBar object.
Any advice would truly be appreciated.
John -
WSsdckapr
AskWoody Lounger -
WSjstevens
AskWoody Lounger -
WSAndrew Cronnolly
AskWoody LoungerNovember 12, 2002 at 3:30 pm #631173I only have a vague recollection of this, but the code is designed to be attached to the listbox on the worksheet, and not to a toolbar button. It should respond when you activate one or other of the listboxes, and if you make multiple selectiond from either, the value should be entered on cells adjacent (row offset) to the relevant linked cell.
Andrew C
-
WSjstevens
AskWoody Lounger -
WSAndrew Cronnolly
AskWoody LoungerNovember 12, 2002 at 8:59 pm #631259John,
Because the ActiveX controls you are using do not support the Application.Caller property, and because of other differences the code needs some amendment. Also you need to set the MultiSelect property of the Listbox to either Multi or Extended (not Single) depending on your exact needs. The following code should get you started :
Private Sub ListBox1_Change() Dim Indx As Long, Items As Long, i As Long Dim oCell As Range Items = ListBox1.ListCount - 1 Set oCell = Range(ListBox1.LinkedCell) Range(oCell, oCell.Offset(Items, 0)).ClearContents For i = 0 To Items If ListBox1.Selected(i) = True Then oCell.Offset(Indx, 0) = ListBox1.List(i) Indx = Indx + 1 End If Next End Sub
Also attached your example with th eabove code using MultiSelectExtended
Andrew
-
WSjstevens
AskWoody Lounger
-
-
-
-
-
H. Legare Coleman
AskWoody PlusJune 25, 2002 at 8:05 pm #596968I found this in the Help file, does it help?
[indent]
Selected Property
Returns or sets the selection state of items in a ListBox.
Syntax
object.Selected( index ) [= Boolean]
The Selected property syntax has these parts:
Part Description
object Required. A valid object.
index Required. An integer with a range from 0 to one less than the number of items in the list.
Boolean Optional. Whether an item is selected.Settings
The settings for Boolean are:
Value Description
True The item is selected.
False The item is not selected.Remarks
The Selected property is useful when users can make multiple selections. You can use this property to determine the selected rows in a multi-select list box. You can also use this property to select or deselect rows in a list from code.
The default value of this property is based on the current selection state of the ListBox.
For single-selection list boxes, the Value or ListIndex properties are recommended for getting and setting the selection. In this case, ListIndex returns the index of the selected item. However, in a multiple selection, ListIndex returns the index of the row contained within the focus rectangle, regardless of whether the row is actually selected.
When a list box control’s MultiSelect property is set to None, only one row can have its Selected property set to True.
Entering a value that is out of range for the index does not generate an error message, but does not set a property for any item in the list.
[/indent]
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Plugged in 24-7
by
CWBillow
1 hour, 22 minutes ago -
Netflix, Apple, BofA websites hijacked with fake help-desk numbers
by
Nibbled To Death By Ducks
4 hours, 45 minutes ago -
Have Copilot there but not taking over the screen in Word
by
CWBillow
1 hour, 55 minutes ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
1 day, 19 hours ago -
Are Macs immune?
by
Susan Bradley
15 hours, 37 minutes ago -
HP Envy and the Function keys
by
CWBillow
1 day, 3 hours ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
2 days, 7 hours ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
2 days, 7 hours ago -
Unable to update to version 22h2
by
04om
22 hours ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
2 days, 14 hours ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
2 days, 14 hours ago -
Very Quarrelsome Taskbar!
by
CWBillow
2 days ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
3 days, 3 hours ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
2 days, 16 hours ago -
Is your battery draining?
by
Susan Bradley
2 hours, 29 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
4 hours, 57 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
3 days, 7 hours ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
17 hours, 52 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
2 days, 16 hours ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
2 days, 8 hours ago -
National scam day
by
Susan Bradley
1 day, 15 hours ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
2 days, 11 hours ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
4 days, 8 hours ago -
Tools to support internet discussions
by
Kathy Stevens
2 days, 21 hours ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
3 days, 23 hours ago -
AI is good sometimes
by
Susan Bradley
4 days, 16 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
4 days, 6 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
5 days, 16 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
5 days, 14 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
5 days, 18 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.