Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default filling userform listbox


Hi,

I would like to create a user form with two list boxes. The first list
box will always contain the same set of values from a worksheet,
therefore I can use a With statement in the UserForm_Initialize() sub
procedure. This is the easy part.

However, what I would really like to do is have the list displayed in
the second list box vary depending on the selection made in the first
list box.

Ie
ListBox1 contains "A, B, C, D" etc.
If the user selects "A", then ListBox2 will contain "1, 2, 3, 4".
However, if the user selects "B", then ListBox2 will actually contain
"X, Y, Z".

Is this possible?
Preferably, I would like the information in ListBox2 to appear as soon
as an item is selected in ListBox1.

Thanks, Simon


--
simonhall
------------------------------------------------------------------------
simonhall's Profile: http://www.excelforum.com/member.php...o&userid=30582
View this thread: http://www.excelforum.com/showthread...hreadid=552106

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default filling userform listbox


Hello Simon,

Here is a method that uses 1 ListBox and a Label on a User Form.
don't think you need a second ListBox if it is only to display data.

When using Columns there are 2 properties that control how the data i
displayed: BoundColumn and TextColumn. BoundColumn controls whic
column is displayed in the ListBox. TextColumn controls which colum
data is returned from.

Set the TextColumn Property of ListBox1 = 2. There are actually
columns of data per line (Row). The user will see only the first colum
and the second will be hidden. When the user clicks on a line, th
Label's Caption will display the second column of the line selected i
ListBox1. Here is the code for the Controls and Events...


Code
-------------------
Private Sub ListBox1_Click()

Label1.Caption = ListBox1.Text

End Sub

Private Sub UserForm_Activate()

With ListBox1
.AddItem
.Column(0, 0) = "A"
.Column(1, 0) = "1,2,3,4"
.AddItem
.Column(0, 1) = "B"
.Column(1, 1) = "X,Y,Z"
End With

End Sub

-------------------


The .AddItem creates a new Row (Line) in the ListBox. The .Column(c, r
places the data in the appropriate Column for that Row. First Row an
Column start at zero.

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=55210

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default filling userform listbox


Hi Leith,

I can get something like that to work.
Such a simple idea, thanks for filling me in.

Simon


--
simonhall
------------------------------------------------------------------------
simonhall's Profile: http://www.excelforum.com/member.php...o&userid=30582
View this thread: http://www.excelforum.com/showthread...hreadid=552106

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
userform listbox cannot get listbox.value to transfer back to main sub [email protected] Excel Programming 1 May 17th 06 09:44 PM
Filling a listbox with transpose of a range from an excel sheet viswanthank Excel Programming 2 June 9th 05 03:37 PM
Activating userform and filling it with data form row where userform is activate Marthijn Beusekom via OfficeKB.com[_2_] Excel Programming 3 May 6th 05 05:44 PM
Problem with Find filling a listbox vba farmer[_2_] Excel Programming 4 October 12th 04 06:55 PM
Filling a listbox depending on font index Trevor[_3_] Excel Programming 0 October 1st 03 08:25 PM


All times are GMT +1. The time now is 03:31 PM.

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"