Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do I retrieve multiple selections from a forms listbox?

I am creating a worksheet in which the users will select choices from a
multi-select listbox. I have been able to do this using VBA code with a
ActiveX listbox from the Controls Toolbar. However, I don't need the
complexity (and associated problems) of an ActiveX control, so I would prefer
to use a listbox from the Forms Toolbar. Unfortunately, with multi-select,
the cell link is inactive, but I have found no instruction on how to link the
user's selections to a spreadsheet.

Can anyone offer suggestions on how to retrieve the user's selections from a
Forms listbox?

Thanks in advance for any help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default How do I retrieve multiple selections from a forms listbox?

"Wheeler" wrote in message
...
I am creating a worksheet in which the users will select choices from a
multi-select listbox. I have been able to do this using VBA code with a
ActiveX listbox from the Controls Toolbar. However, I don't need the
complexity (and associated problems) of an ActiveX control, so I would
prefer
to use a listbox from the Forms Toolbar. Unfortunately, with multi-select,
the cell link is inactive, but I have found no instruction on how to link
the
user's selections to a spreadsheet.


There's no way to automatically link the results of a multiselect
ListBox of either type directly to worksheet cells. You have to loop the
whole list and use the Selected property to determine which items are
selected. Here's an example:

Sub GetSelections()
Dim lIndex As Long
Dim szSelections As String
For lIndex = 1 To Sheet1.ListBoxes(1).ListCount
If Sheet1.ListBoxes(1).Selected(lIndex) Then
szSelections = szSelections & _
Sheet1.ListBoxes(1).List(lIndex) & vbLf
End If
Next lIndex
If Len(szSelections) 0 Then MsgBox szSelections
End Sub

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do I retrieve multiple selections from a forms listbox?

Thanks for the response Rob.

I knew I had to loop through, but I was missing something in the code I was
trying to use. Using your example, I was able to figure out what I needed.

Thanks again, very much!

Wheeler

"Rob Bovey" wrote:

"Wheeler" wrote in message
...
I am creating a worksheet in which the users will select choices from a
multi-select listbox. I have been able to do this using VBA code with a
ActiveX listbox from the Controls Toolbar. However, I don't need the
complexity (and associated problems) of an ActiveX control, so I would
prefer
to use a listbox from the Forms Toolbar. Unfortunately, with multi-select,
the cell link is inactive, but I have found no instruction on how to link
the
user's selections to a spreadsheet.


There's no way to automatically link the results of a multiselect
ListBox of either type directly to worksheet cells. You have to loop the
whole list and use the Selected property to determine which items are
selected. Here's an example:

Sub GetSelections()
Dim lIndex As Long
Dim szSelections As String
For lIndex = 1 To Sheet1.ListBoxes(1).ListCount
If Sheet1.ListBoxes(1).Selected(lIndex) Then
szSelections = szSelections & _
Sheet1.ListBoxes(1).List(lIndex) & vbLf
End If
Next lIndex
If Len(szSelections) 0 Then MsgBox szSelections
End Sub

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Chart from Userform ListBox selections Corey Charts and Charting in Excel 2 September 8th 08 05:53 AM
Forms with conditions & mandatory selections Bec[_3_] Excel Worksheet Functions 0 July 16th 07 06:38 AM
Display selections from a listbox in a message box Excel-erate2004[_35_] Excel Programming 2 September 6th 04 12:48 PM
Jumping to chart based on listbox selections ChrisMD Excel Programming 0 July 7th 04 04:42 PM
changing foreground color of listbox w/o losing selections PatFinegan[_13_] Excel Programming 0 May 10th 04 09:30 PM


All times are GMT +1. The time now is 05:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"