LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Populating One Listbox from a second listbox

On Jun 18, 8:17 pm, "Steven Taylor" wrote:
Hi,

I would really appreciate some help with the following:

1. I would like to create a user form that has two list boxes.

2. The first list box should provide a listing of all open excel workbooks.

3. The second list box should display the sheets of the workbook that

is selected in the first list box.

4. The code should prevent duplicate workbooks or worksheets from

being displayed in the list boxes.

I am working with Windows XP and Excel 2002.

Any advice on how to accomplished the above would be greatly appreciated.

Thanks,

Steve


Hello Steve,

This code should get you going. It assumes you have a UserForm named
UserForm1 with 2 ListBoxes on it named ListBox1, and ListBox2. When
the UserForm is Activated, ListBox1 is loaded with names of the Open
Workbooks. Once a Workbook has been selected, ListBox2 is loaded with
the all the sheet names in the choosen workbook.

'Begin Macro Code
Private Sub ListBox1_Click()

Dim Sht As Sheet
Dim Wkb As Workbook

ListBox2.Clear
Set Wkb = Workbooks(ListBox1.Value)

For Each Sht In Wkb.Sheets
ListBox2.AddItem Sht.Name
Next Sht

End Sub

Private Sub UserForm_Activate()

Dim Wkb As Workbook

For Each Wkb In Application.Workbooks
ListBox1.AddItem Wkb.Name
Next Wkb

End Sub
'End Macro Code...

Sincerely,
Leith Ross


 
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 listbox Mick[_2_] Excel Discussion (Misc queries) 1 May 14th 08 10:48 PM
populating a listbox enyaw Excel Programming 3 November 28th 06 06:48 AM
Populating listbox Andy Brown Excel Programming 3 August 16th 04 05:40 PM
Populating a ListBox ToddG Excel Programming 1 June 24th 04 03:18 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


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