Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Storing the results of a list box

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Storing the results of a list box

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Storing the results of a list box

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default Storing the results of a list box

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Storing the results of a list box

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Storing the results of a list box

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there an excel template for storing laboratory results Ian Excel Discussion (Misc queries) 1 January 8th 09 10:59 PM
Storing Macro Results daphoenix Excel Worksheet Functions 1 June 26th 08 05:48 PM
Filter the results of a list based on a previous vlookup against the same list Mizpah Excel Worksheet Functions 2 August 18th 06 10:28 AM
How to Update filter criteria from list and storing the query to another worksheet changeable[_3_] Excel Programming 1 November 1st 04 02:11 PM
How can I list the results of my macro without overwritng previous results? mattip Excel Programming 3 November 28th 03 03:45 AM


All times are GMT +1. The time now is 09:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"