Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What is the best method of storing the selected results of a listbox? to a
variable? I am calling a userform from another userform and I need to pass back the selections of a listbox to the first userform, not for display but rather for later processing. I have tried declaring a public variable as type ListBox, then tried Set PublicListBox = ListBox i get a type mismatch error, an ideas? Thanks Simon Shaw |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On the first userform, declare a public string
Public myVal As String In the second, set it say on the Listbox click Userform1.myVal = Me.Listbox1.Value -- HTH Bob Phillips "Simon Shaw" <simonATsimonstoolsDOTcom wrote in message ... What is the best method of storing the selected results of a listbox? to a variable? I am calling a userform from another userform and I need to pass back the selections of a listbox to the first userform, not for display but rather for later processing. I have tried declaring a public variable as type ListBox, then tried Set PublicListBox = ListBox i get a type mismatch error, an ideas? Thanks Simon Shaw |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This doesn't work as he Listbox is a multiselect.
I also want to be able to re-populate the listbox with the previous selection if the user opens the second userform again. Thanks "Bob Phillips" wrote: On the first userform, declare a public string Public myVal As String In the second, set it say on the Listbox click Userform1.myVal = Me.Listbox1.Value -- HTH Bob Phillips "Simon Shaw" <simonATsimonstoolsDOTcom wrote in message ... What is the best method of storing the selected results of a listbox? to a variable? I am calling a userform from another userform and I need to pass back the selections of a listbox to the first userform, not for display but rather for later processing. I have tried declaring a public variable as type ListBox, then tried Set PublicListBox = ListBox i get a type mismatch error, an ideas? Thanks Simon Shaw |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Simon,
Try saving to the dynamic Array I have named Ar(): Private Sub ListBox1_Change() Dim i As Long Dim Ar() As String ReDim Ar(0) With Me.ListBox1 For i = 0 To .ListCount - 1 If .Selected(i) Then ReDim Preserve Ar(UBound(Ar) + 1) Ar(UBound(Ar)) = .List(i) End If Next i End With End Sub "Simon Shaw" <simonATsimonstoolsDOTcom wrote in message ... This doesn't work as he Listbox is a multiselect. I also want to be able to re-populate the listbox with the previous selection if the user opens the second userform again. Thanks "Bob Phillips" wrote: On the first userform, declare a public string Public myVal As String In the second, set it say on the Listbox click Userform1.myVal = Me.Listbox1.Value -- HTH Bob Phillips "Simon Shaw" <simonATsimonstoolsDOTcom wrote in message ... What is the best method of storing the selected results of a listbox? to a variable? I am calling a userform from another userform and I need to pass back the selections of a listbox to the first userform, not for display but rather for later processing. I have tried declaring a public variable as type ListBox, then tried Set PublicListBox = ListBox i get a type mismatch error, an ideas? Thanks Simon Shaw |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
While trying this I came up with very similar code to what William
Benson had. In order to have the first form see the array, I had to declare it public in a code module, like Public Ar() As String . Not sure if there is any other way. Couldn't make it public in a form. Sometimes if I need data to be shared, I store it to cells in a worksheet, then every module, form and control can see it. To re-populate the listbox with the results, try this 'Somewhere in the first form, before showing the second form. 'Note that the array must have been redim'ed and have values. Dim i As Integer if <condition to repopulate list box then Form2.ListBox1.Clear For i = 1 To UBound(Ar) Form2.ListBox1.AddItem (Ar(i)) Next endif Form2.Show Len Simon Shaw wrote: This doesn't work as he Listbox is a multiselect. I also want to be able to re-populate the listbox with the previous selection if the user opens the second userform again. Thanks |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Actually, I was being dumb, you don't need a v ariable, yopu could access
the control directly. Similalrly, if it multi-select, you could in Userform2 use Dim i As Long With UserForm1.ListBox1 For i = 0 To .ListCount - 1 If .Selected(i) Then MsgBox .Value End If Next i End With -- HTH Bob Phillips "Simon Shaw" <simonATsimonstoolsDOTcom wrote in message ... This doesn't work as he Listbox is a multiselect. I also want to be able to re-populate the listbox with the previous selection if the user opens the second userform again. Thanks "Bob Phillips" wrote: On the first userform, declare a public string Public myVal As String In the second, set it say on the Listbox click Userform1.myVal = Me.Listbox1.Value -- HTH Bob Phillips "Simon Shaw" <simonATsimonstoolsDOTcom wrote in message ... What is the best method of storing the selected results of a listbox? to a variable? I am calling a userform from another userform and I need to pass back the selections of a listbox to the first userform, not for display but rather for later processing. I have tried declaring a public variable as type ListBox, then tried Set PublicListBox = ListBox i get a type mismatch error, an ideas? Thanks Simon Shaw |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Is there an excel template for storing laboratory results | Excel Discussion (Misc queries) | |||
Storing Macro Results | Excel Worksheet Functions | |||
Filter the results of a list based on a previous vlookup against the same list | Excel Worksheet Functions | |||
How to Update filter criteria from list and storing the query to another worksheet | Excel Programming | |||
How can I list the results of my macro without overwritng previous results? | Excel Programming |