Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Code to import data based on selection in two listboxes

Hi All,



I would appreciate some help with the following:



1. I have a user form with two list boxes.

2. The first list box displays the name of all open excel workbooks.

3. The second list box will display the sheets of the workbook the user
selects

from the first list box.

4. I would like to add an import button to my user form.

5. The import button will import the data from the workbook selected in

the first list box and from the sheet selected in the second list box into

sheet1 of the template workbook where the user form is displayed.



All comments and suggestion welcome.



Thanks,



Steve



PS I am using excel 2002 and windows XP.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default Code to import data based on selection in two listboxes

Hi,

Try to add these following codes to your prject:

'1. I have a user form with two list boxes.
Sub RetreiveShtName(BookSource As Workbook, _
BookDestination As Workbook)
Dim Wks As Worksheet

'2. The first list box displays the name of all open excel workbooks.
For Each Wks In BookSource.Sheets
ListBox1.AddItem BookSource.Name & "-" & Wks.Name
Next Wks

'3. The second list box will display the sheets of the workbook
'the user selects
For Each Wks In BookDestination.Sheets
ListBox2.AddItem BookDestination.Name & "-" & Wks.Name
Next Wks

'to avoid Null for listbox value that error may occured when
'commandbutton1_click (if null)
ListBox1.ListIndex = 0
ListBox2.ListIndex = 0

End Sub

'4. I would like to add an import button to my user form.
Sub RetreiveData(dSource As Range, dDest As Range)
dSource.Copy Destination:=dDest
End Sub

'5. The import button will import the data from the workbook
'selected in
'the first list box and from the sheet selected in the second list
'box into
'sheet1 of the template workbook where the user form is displayed.

Private Sub CommandButton1_Click()
Dim SpltName1 As Variant
Dim SpltName2 As Variant

SpltName1 = Split(ListBox1, "-")
SpltName2 = Split(ListBox2, "-")

RetreiveData _
Workbooks(SpltName1(0)).Sheets(SpltName1(1)).Range ("A1"), _
Workbooks(SpltName2(0)).Sheets(SpltName2(1)).Range ("A1")

End Sub

Private Sub UserForm_Initialize()
RetreiveShtName Workbooks("book1.xls"), Workbooks("book2.xls")
End Sub

I hope the help you...

--

Regards,

Halim


"Steven Taylor" wrote:

Hi All,



I would appreciate some help with the following:



1. I have a user form with two list boxes.

2. The first list box displays the name of all open excel workbooks.

3. The second list box will display the sheets of the workbook the user
selects

from the first list box.

4. I would like to add an import button to my user form.

5. The import button will import the data from the workbook selected in

the first list box and from the sheet selected in the second list box into

sheet1 of the template workbook where the user form is displayed.



All comments and suggestion welcome.



Thanks,



Steve



PS I am using excel 2002 and windows XP.




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
import worksheet based on a selection John Casteel Excel Discussion (Misc queries) 0 June 15th 06 06:48 AM
How to import data based on a variable kjp55 Excel Worksheet Functions 8 June 9th 06 12:34 AM
How do I refresh the selection listboxes on a pivot table? WWW.CS Excel Discussion (Misc queries) 2 February 23rd 05 11:33 AM
Single Selection ListBoxes jacqui[_2_] Excel Programming 4 February 10th 04 03:16 PM
VBA code for Excel 2000, IF procedures and listboxes Bob[_22_] Excel Programming 0 July 9th 03 05:09 PM


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