Load Userform Listbox list from worksheet cell

Celticfc

Board Regular
Joined
Feb 28, 2016
Messages
153
Hi,

A1 has a list of client names with debts; B1 has a list of all clients in our business. Names are separated by commas.

I have a userform with 2 listboxes. Listbox1 should show the list of clients with debts;
Listbox2 should lists the clients without debts.

Here’s an example:

A1: Client1, Client 3, Client 5,

B1: Client 1, Client 2, Client 3, Client 4, Client 5

Therefore, Listbox1 should list everything in A1, Listbox2 should only list Client 2 and Client 4.

Would really appreciate support, thank you.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try this in your Userform Code Module:-
NB:- Your 2 set of data do not match (Two places) where they should ("Client 1, and Client1" and "Client 5, and Client 5"")

Code:
Private [COLOR=navy]Sub[/COLOR] UserForm_Initialize()
[COLOR=navy]Dim[/COLOR] Sp [COLOR=navy]As[/COLOR] Variant, Sp1 [COLOR=navy]As[/COLOR] Variant, Ray [COLOR=navy]As[/COLOR] Variant, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
 Sp = Split([B1], ", ")
    Sp1 = Split([a1], ", ")
        [COLOR=navy]For[/COLOR] n = 0 To UBound(Sp1)
            Ray = (Filter(Sp, Sp1(n), False))
            Sp = Ray
        [COLOR=navy]Next[/COLOR] n

ListBox1.List = Sp1
ListBox2.List = Ray
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Try this in your Userform Code Module:-
NB:- Your 2 set of data do not match (Two places) where they should ("Client 1, and Client1" and "Client 5, and Client 5"")

Code:
Private [COLOR=navy]Sub[/COLOR] UserForm_Initialize()
[COLOR=navy]Dim[/COLOR] Sp [COLOR=navy]As[/COLOR] Variant, Sp1 [COLOR=navy]As[/COLOR] Variant, Ray [COLOR=navy]As[/COLOR] Variant, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
 Sp = Split([B1], ", ")
    Sp1 = Split([a1], ", ")
        [COLOR=navy]For[/COLOR] n = 0 To UBound(Sp1)
            Ray = (Filter(Sp, Sp1(n), False))
            Sp = Ray
        [COLOR=navy]Next[/COLOR] n

ListBox1.List = Sp1
ListBox2.List = Ray
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
Hi, this works great however when listbox1 or 2 are empty(as I transfer contents between them, one of them can become empty), I amgetting an error when sending listbox contents to C1: Error 381.
How can I add a condition that if either list boxes areempty, it should just paste blank in C1 etc.
Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top