Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 390
Default Data Array in Listbox?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Data Array in Listbox?

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" wrote in message
...
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
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
populating a listbox from an array Graham Whitehead Excel Programming 2 August 2nd 06 01:11 PM
How do I pass an array to a listbox? Titus A Ducksass - AKA broken-record Excel Programming 4 March 23rd 05 07:20 PM
How to sort ListBox or Array? NEED Excel Programming 1 December 16th 04 08:13 PM
ListBox array Neil Excel Programming 1 November 24th 03 11:34 AM
Listbox and Array questions Stuart[_5_] Excel Programming 4 September 23rd 03 11:04 PM


All times are GMT +1. The time now is 08:42 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"