PC Review


Reply
Thread Tools Rate Thread

Data Array in Listbox?

 
 
=?Utf-8?B?TWF4?=
Guest
Posts: n/a
 
      29th Oct 2007
Help this noob out...

I want to place data in an array in a listbox. Then I want a user to select
one or multiple values within that text box.

1) How do I initialize the listbox?
2) How do populate the listbox with the array contents?
3) How do I store the user selection into another array?

--
Thanks!
Max
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      29th Oct 2007
Max,

Try the code below in the userform's codemodule. Assumes that you have a 2 column listbox named
Listbox1 on your userform, with its multiselect property set to multi.

HTH,
Bernie
MS Excel MVP

Option Explicit


Private Sub UserForm_Initialize()
'Populate the listbox with some values
Dim i As Integer
Dim j As Integer
Dim myArr(1 To 10, 1 To 2) As Integer

For i = 1 To 10
For j = 1 To 2
myArr(i, j) = i * 2 + IIf(j = 1, 100, 1)
Next j
Next i

Me.ListBox1.List = myArr
End Sub

'Get the selection of the listbox
Private Sub CommandButton1_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim mySel(1 To 10, 1 To 2) As Integer

i = 1

With Me.ListBox1
For k = 0 To .ListCount - 1
If .Selected(k) = True Then
mySel(i, 1) = Me.ListBox1.List(k, 0)
mySel(i, 2) = Me.ListBox1.List(k, 1)
i = i + 1
End If
Next k
End With

For j = 1 To i - 1
MsgBox "Selected " & mySel(j, 1) & ", " & mySel(j, 2)
Next j

End Sub

"Max" <(E-Mail Removed)> wrote in message
news:45FC1BDC-8E29-4B68-9BD4-(E-Mail Removed)...
> Help this noob out...
>
> I want to place data in an array in a listbox. Then I want a user to select
> one or multiple values within that text box.
>
> 1) How do I initialize the listbox?
> 2) How do populate the listbox with the array contents?
> 3) How do I store the user selection into another array?
>
> --
> Thanks!
> Max



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox to Array J Streger Microsoft Excel Programming 2 12th Mar 2008 08:40 PM
array to listbox Mike Microsoft ASP .NET 18 9th Jul 2007 07:54 PM
Data binding an array to a listbox A. Spiehler Microsoft C# .NET 1 26th Apr 2006 10:58 PM
Can you move highlighted data from one listbox to another listbox on the same form? Col. Forbin Microsoft Access 2 24th Sep 2004 07:51 PM
ListBox array Neil Microsoft Excel Programming 1 24th Nov 2003 11:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:54 PM.