View Full Version : Solved: ListBox as a Variable?
pcsparky
11-25-2009, 09:46 AM
I have 2 forms Userform1 & Userform2 that each have a listbox, lBox1 & lBox2 respectively.
Each listbox needs to be filled with the same data so is it possible somehow to create a Sub Routine in another Module and call that from each userform?
This is what I wanted to do but if it is possible I don't know how to make the listbox names Userform1.lBox1 & Userform2.lBox2 as variables.
Bob Phillips
11-25-2009, 09:55 AM
Yes, somthing like this
Userform
Call LoadListBox (Me.ListBox1)
Module
Public Function LoadListBox(ByRef Listbox As MSForms.Listbox)
With Listbox
.AddItem "A"
.AddItem "B"
'etc.
End With
End Function
mdmackillop
11-25-2009, 09:57 AM
Assign a Public Variable in a Standard Module. When either listbox is clicked, use the result to change the variable, perhaps to the ListIndex if both lists are the same.
pcsparky
11-25-2009, 10:23 AM
Brilliant. Than you both. Easy when you know how :thumb
pcsparky
11-26-2009, 02:26 AM
Sorry I have another question, now that I've come across this situation again.
How do I adapt your answer where I have 3 listboxes on the same userform?
Bob Phillips
11-26-2009, 03:03 AM
Mine allows for any number of listboxes, you just pass the relevannt listbox control in the call.
pcsparky
11-26-2009, 04:02 AM
Thank you
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.