ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   listbox with multiple selections (https://www.excelbanter.com/excel-programming/429196-listbox-multiple-selections.html)

DaveL

listbox with multiple selections
 
I have built a listbox that allows multiple selections and I have put those
slelections into an array. At this point I want to unload the userform and
use that array in a macro outside of the userform. However, I can't find a
way to access the array I created in the userform. It appears I have to
write the selections to a worksheet, then use a macro to read and write them
into an array and then delete the worksheet in order to move on and do what I
want with an array of selected items. Is that right or am I missing
something?

Robert McCurdy

listbox with multiple selections
 
Hi Dave,

Create a button on the Userform.
The code should look something like this:

Cells(2,1).Resize(ubound(YourArray,1),ubound(YourA rray,2)) = YourArray

YourArray should get placed from cell A2 with the above example.
You will - of course - require a bit of error handling here. :)


Regards
Robert McCurdy
"DaveL" wrote in message
...
I have built a listbox that allows multiple selections and I have put those
slelections into an array. At this point I want to unload the userform
and
use that array in a macro outside of the userform. However, I can't find
a
way to access the array I created in the userform. It appears I have to
write the selections to a worksheet, then use a macro to read and write
them
into an array and then delete the worksheet in order to move on and do
what I
want with an array of selected items. Is that right or am I missing
something?




DaveL

listbox with multiple selections
 
Robert,

Thanks for the recommendation. I did what you recommended, but it still
requires taking the selceted items, putting them in a worksheet and then
writing them into another array outside the userform. i was just hoping for
a cleaner more direct route but I guess that's not possible when you are in a
userform.

Dave

"Robert McCurdy" wrote:

Hi Dave,

Create a button on the Userform.
The code should look something like this:

Cells(2,1).Resize(ubound(YourArray,1),ubound(YourA rray,2)) = YourArray

YourArray should get placed from cell A2 with the above example.
You will - of course - require a bit of error handling here. :)


Regards
Robert McCurdy
"DaveL" wrote in message
...
I have built a listbox that allows multiple selections and I have put those
slelections into an array. At this point I want to unload the userform
and
use that array in a macro outside of the userform. However, I can't find
a
way to access the array I created in the userform. It appears I have to
write the selections to a worksheet, then use a macro to read and write
them
into an array and then delete the worksheet in order to move on and do
what I
want with an array of selected items. Is that right or am I missing
something?





royUK[_133_]

listbox with multiple selections
 

You need to create a Global Variable in a Standard Module


Code:
--------------------

Public MyArray as variant

--------------------


Set the array in the userform & it willbe available when the form is
closed


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=102032


DaveL

listbox with multiple selections
 
rouUK,

OK, that made me look foolish. I don't know why I had it in my head that
a variable scoped as public wouldn't work with a userform. This makes it
clean and easy.

"royUK" wrote:


You need to create a Global Variable in a Standard Module


Code:
--------------------

Public MyArray as variant

--------------------


Set the array in the userform & it willbe available when the form is
closed


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=102032



royUK[_134_]

listbox with multiple selections
 

We all make mistakes. Glad it helped

HOW TO GET FURTHER HELP WITH A WORKBOOK
For further help with it why not join our forums (shown in
the link below) it's completely free, if you do join you will have the
opportunity to add attachmnets to your posts so you can add workbooks to
better illustrate your problems and get help directly with them. Also if
you do join please post in this thread (link found below) so that people
who have been following or helping with this query can continue to do
so. :)


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=102032



All times are GMT +1. The time now is 12:13 AM.

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