UserForm Listbox not functioning correctly.

P

PaulW

I've got a "Reset" button in my userform. Basically, Listbox1 is
automatically populated via all the headers in row 1 on the spreadsheet, then
you can select some of the headers and move them to Listbox2 with a command
button. On page 2 of the userform Listbox3 is a copy of Listbox2 (when
something is added to Listbox2 its also added to listbox3)
You can then sort the order with more listboxes and command buttons. Part of
this sorting process removes items from Listbox3 so you can't sort the same
thing twice.
I want a reset button to return Listbox3 to what it originally was (a copy
of Listbox2) so you can start the sort process again easily.

The first loop removes all the items from Listbox3, and the second one
should copy everything from Listbox2 into Listbox3. But currently it copies
the first item only (although it copies it until the loop is completed) I can
change the (i) to a number and it'll copy that index over, so it looks like
theres something wrong with the loop, or i isn't updating, or
"ListBox3.AddItem ListBox2.List(i)" is adding everything in 1 go, rather than
1 at a time.

This is my first Userform attempt, so its quite possible that I've gone
wrong somewhere with the wrong word.

Do Until ListBox3.ListCount = 0
ListBox3.RemoveItem 0
Loop

Do Until ListBox2.ListCount = ListBox3.ListCount
i = 0
ListBox3.AddItem ListBox2.List(i)
i = i + 1
Loop
 
J

Jim Rech

You keep resetting i = 0. Pull that out of the Do Loop

--
Jim
| I've got a "Reset" button in my userform. Basically, Listbox1 is
| automatically populated via all the headers in row 1 on the spreadsheet,
then
| you can select some of the headers and move them to Listbox2 with a
command
| button. On page 2 of the userform Listbox3 is a copy of Listbox2 (when
| something is added to Listbox2 its also added to listbox3)
| You can then sort the order with more listboxes and command buttons. Part
of
| this sorting process removes items from Listbox3 so you can't sort the
same
| thing twice.
| I want a reset button to return Listbox3 to what it originally was (a copy
| of Listbox2) so you can start the sort process again easily.
|
| The first loop removes all the items from Listbox3, and the second one
| should copy everything from Listbox2 into Listbox3. But currently it
copies
| the first item only (although it copies it until the loop is completed) I
can
| change the (i) to a number and it'll copy that index over, so it looks
like
| theres something wrong with the loop, or i isn't updating, or
| "ListBox3.AddItem ListBox2.List(i)" is adding everything in 1 go, rather
than
| 1 at a time.
|
| This is my first Userform attempt, so its quite possible that I've gone
| wrong somewhere with the wrong word.
|
| Do Until ListBox3.ListCount = 0
| ListBox3.RemoveItem 0
| Loop
|
| Do Until ListBox2.ListCount = ListBox3.ListCount
| i = 0
| ListBox3.AddItem ListBox2.List(i)
| i = i + 1
| Loop
 

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