PDA

View Full Version : [SOLVED:] Two Listbox



Emily
12-21-2004, 08:13 PM
Suppose I have two similar worksheets, 4 Columns , 22 rows include 2 header rows.

Can I have those data list in Userform with two listboxes, i.e. ListBox1 and ListBox2 simultantously?

Also, is there any method to show two header rows?

Regards.
Emily

Jacob Hilderbrand
12-21-2004, 08:31 PM
For each ListBox set the RowSource for the data you want. Also set the ColumnCount Property to 4.

The RowSource Property cold be something like this:


=Sheet1!A1:D23
=Sheet2!A1:D23

Emily
12-21-2004, 09:51 PM
Thanks for your reply, but the code below shows the same data (ListBox2 data), would you please help me to figure it out. Thanks


Private Sub UserForm_Initialize()
With Me.ListBox1
.Clear
.ColumnCount = 4
.ColumnWidths = "40,80,80,40"
.ColumnHeads = True
.RowSource = Sheet6.Range("A3:D25").Address
End With
With Me.ListBox2
.Clear
.ColumnCount = 4
.ColumnWidths = "40,80,80,40"
.ColumnHeads = True
.RowSource = Sheet7.Range("A3:D25").Address
End With
End Sub

Jacob Hilderbrand
12-21-2004, 11:47 PM
Try this:


Private Sub UserForm_Initialize()
With Me.ListBox1
.Clear
.ColumnCount = 4
.ColumnWidths = "40,80,80,40"
.ColumnHeads = True
.RowSource = "Sheet6!A3:D25"
End With
With Me.ListBox2
.Clear
.ColumnCount = 4
.ColumnWidths = "40,80,80,40"
.ColumnHeads = True
.RowSource = "Sheet7!A3:D25"
End With
End Sub

Emily
12-22-2004, 03:22 AM
Thanks for your reply, but it shown invalid property

Jacob Hilderbrand
12-22-2004, 03:46 AM
See if this attachment works for you.

Emily
12-22-2004, 06:16 PM
Thanks, your file works.
I will check my code later.

Jacob Hilderbrand
12-22-2004, 06:52 PM
You're Welcome :)

Take Care

Emily
12-23-2004, 04:44 AM
Hi DRJ

Can I continue this question, I found error due to the sheet name, for example:

.RowSource = "Test(1)Data!A3:E22"

It works when changed to

.RowSource = "TestData!A3:E22"

Do you know why?

Jacob Hilderbrand
12-23-2004, 04:59 AM
Parentheses are not allowed. Excel has trouble with some sheet names. Like some formulas will not work if there is a space in the sheet name. You could name the sheet "Test1Data" or something along those lines.

Emily
12-23-2004, 06:06 AM
Thanks a lot
I found that it works when changed to


.RowSource = " 'Test(1)Data'!A3:E22"