View Full Version : VBA and Excel - Multiple Values from a Listbox into a Named Range


nashat21
11-12-2003, 12:14 PM
A friend is trying to paste multiple values selected from a listbox into a named range. Is there any way this can be done?

Any and all help will be greatly appreciated.

Nashat

Pat Hartman
11-12-2003, 10:36 PM
You need to obtain the members of the selected collection one at a time so it would probably be easiest to paste them as they are identified.
For Each i In Me.YourControl.ItemsSelected
'code to insert into sheet cell
Next i

nashat21
11-13-2003, 05:39 AM
That seems to be the error I am getting. Apparently, it does not recognize the ListBox1 as an object in Me or ThisWorkbook or Sheet1.

Can you help?

Nashat

Pat Hartman
11-15-2003, 10:46 AM
The code needs to be within the form for the Me. reference to work since Me refers to the active form. If your code is running in a standard module, you will need to reference the form field by its full name - Forms!YourForm!YourControl - or pass a reference to the control as an argument when you run the sub.

If that doesn't help, you'll need to post your code for people to look at.