Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tjh tjh is offline
external usenet poster
 
Posts: 96
Default Listbox - Store values

Hello,

I would like to have the values which the user selects from a listbox stored
to memory while the macro is running. Essentially, I want the user to make a
selection from the list. Once they make their selection, use a radial button
to decide if they need to make another selection from the list. If they
choose yes, then the listbox will reappear, allowing them to make their next
selections. Each time I would like their selections to be stored to memory as
a different variable, so that the code can later reference each of their
selections. This seems like it is somewhat redundant and unnecessary, since
they can choose multiple selections at one time. However, each time the
listbox appears the user will be making multiple selections and grouping
them. That is why the box would need to reappear again (for the next group).
The only other way I can think of doing this would be to place a textbox in
the listbox allowing them to group their selections. I do not know how to do
this either, but it would be more efficient.

Any Suggestions

Thank you




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Listbox - Store values

I think I would use a hidden worksheet.

You could use each row to show what was chosen out of your listbox.

But this seemed to work ok for me...

I built a userform with a listbox and 3 buttons (cancel, process this selection,
and Finished).

This is all behind that userform:

Option Explicit
Dim myArray() As Variant
Dim ArrayCtr As Long
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()

Dim aCtr As Long
Dim lbCtr As Long
Dim mySubArray() As Variant

ReDim Preserve mySubArray(1 To Me.ListBox1.ListCount)

With Me.ListBox1
For lbCtr = 1 To .ListCount
mySubArray(lbCtr) = Me.ListBox1.Selected(lbCtr - 1)
.Selected(lbCtr - 1) = False
Next lbCtr
End With

myArray(ArrayCtr) = mySubArray
ReDim Preserve myArray(LBound(myArray) To UBound(myArray) + 1)
ArrayCtr = ArrayCtr + 1
'arrayctr is 1 too many, but so is the ubound(myarray)
'but we're ready for the next time.

End Sub
Private Sub CommandButton3_Click()

Dim aCtr As Long
Dim sCtr As Long

If ArrayCtr = 1 Then
'nothing has ever been chosen
MsgBox "Nothing selected"
Exit Sub 'or unload me
End If

'we have one too many, so don't do the last one!
For aCtr = LBound(myArray) To UBound(myArray) - 1
For sCtr = LBound(myArray(aCtr)) To UBound(myArray(aCtr))
MsgBox "time #: " & aCtr & "--Option#: " _
& sCtr & " was chosen: " & myArray(aCtr)(sCtr)
Next sCtr
Next aCtr

Unload Me

End Sub
Private Sub UserForm_Initialize()
ReDim myArray(1 To 1)
ArrayCtr = 1
Me.CommandButton1.Caption = "Cancel"
Me.CommandButton2.Caption = "Process" & vbLf & "This Choice"
Me.CommandButton3.Caption = "Finished"

With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
End With
End Sub

It essentially makes an array of arrays--each time through a "subarray" is
created of true/falses depending on what they selected.

After that "subarray" is built, it's added as a new member in that bigger array.


=========
If you used a worksheet (hidden), you could clear all the cells when the
userform loads.
Each time the user clicks process, just increment the row number.
Then use each cell in the row to hold True/false depending on what was chosen by
the user.





tjh wrote:

Hello,

I would like to have the values which the user selects from a listbox stored
to memory while the macro is running. Essentially, I want the user to make a
selection from the list. Once they make their selection, use a radial button
to decide if they need to make another selection from the list. If they
choose yes, then the listbox will reappear, allowing them to make their next
selections. Each time I would like their selections to be stored to memory as
a different variable, so that the code can later reference each of their
selections. This seems like it is somewhat redundant and unnecessary, since
they can choose multiple selections at one time. However, each time the
listbox appears the user will be making multiple selections and grouping
them. That is why the box would need to reappear again (for the next group).
The only other way I can think of doing this would be to place a textbox in
the listbox allowing them to group their selections. I do not know how to do
this either, but it would be more efficient.

Any Suggestions

Thank you


--

Dave Peterson
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
How to Periodically Store/Save Excel DDE Values ** Excel Discussion (Misc queries) 1 August 10th 07 09:17 PM
Need to store changing values from one cell Emmie Excel Discussion (Misc queries) 5 September 17th 06 08:10 PM
Store values of a dynamically changing cell Yogesh Excel Worksheet Functions 0 August 4th 05 06:40 PM
ReDim to store values so they are not used again hotherps[_16_] Excel Programming 0 February 18th 04 06:34 PM
update and store new high values jack[_5_] Excel Programming 0 July 10th 03 01:22 AM


All times are GMT +1. The time now is 08:12 AM.

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

About Us

"It's about Microsoft Excel"