listbox with multiple selections

D

DaveL

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?
 
R

Robert McCurdy

Hi Dave,

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

Cells(2,1).Resize(ubound(YourArray,1),ubound(YourArray,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
 
D

DaveL

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
 
R

royUK

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
 
D

DaveL

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.
 
R

royUK

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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top