ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Exiting listboxes in a userform (https://www.excelbanter.com/excel-programming/425669-exiting-listboxes-userform.html)

nir020

Exiting listboxes in a userform
 
I have created a userform in Excel which contains a listbox to which the user
can make multi selections.

Is it possible to include some code that will when the user exits the form
will only show the elements of the userform that have been selected and will
hide the elements that have not been selected.

Thanks

Rick Rothstein

Exiting listboxes in a userform
 
You didn't say where you wanted to "show" the selected items at when the
UserForm is closed. Here is code that puts the selected items into an array
in code... you can use that to see how to read the selected items (the
For..Next loop is the key to that) and then put them wherever it is you
wanted them to go...

Dim X As Long
Dim Index As Long
Dim SelectedItems() As String
With Me.ListBox1
ReDim SelectedItems(0 To .ListCount)
For X = 0 To .ListCount - 1
If .Selected(X) Then
SelectedItems(Index) = .List(X)
Index = Index + 1
End If
Next
ReDim Preserve SelectedItems(0 To Index - 1)
End With

--
Rick (MVP - Excel)


"nir020" wrote in message
...
I have created a userform in Excel which contains a listbox to which the
user
can make multi selections.

Is it possible to include some code that will when the user exits the form
will only show the elements of the userform that have been selected and
will
hide the elements that have not been selected.

Thanks




All times are GMT +1. The time now is 06:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com