LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import data into seperate sheets

Hi guys,

The piece of code that i am using here, imports data from 3 externa
files into one worksheet. Could someone tell me how the code would loo
if i were to put the data from each file into seperate worksheets?

Sub Open3_v2()
Dim i As Integer

'Clear out the existing data
Worksheets("Data").UsedRange.EntireRow.Delete

'Get the 3 data files
For i = 1 To 3
OpenFile
Next
End Sub

Sub OpenFile()
Dim strFile As String
Dim wbkData As Workbook

'Locate the file - quit if user presses cancel
strFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls"
, "Select file", "OK")
If Dir(strFile) = "" Then Exit Sub

'Open the file
Set wbkData = Workbooks.Open(strFile)

'Copy all the data from the one sheet
wbkData.Activate
ActiveSheet.UsedRange.Select
Selection.Copy

'Come back to this workbook and paste the data at the bottom
ThisWorkbook.Activate
Worksheets("Data").Activate
Cells(ActiveSheet.UsedRange.Rows.Count + 1, 1).Select
ActiveSheet.Paste

'Close the data file
wbkData.Close False

'Free up used space in memory
Set wbkData = Nothing
End Sub

Thanks in advance,
Cathal

--
Message posted from http://www.ExcelForum.com

 
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
add two cells from seperate work sheets into a cell on seperate wo lar Excel Worksheet Functions 6 April 27th 10 06:54 PM
Splitting data from sheets into seperate workbooks based on formul bUncE Excel Worksheet Functions 1 September 7th 07 05:55 PM
Auto insert data to seperate sheets? greig2000_uk New Users to Excel 2 May 27th 06 01:10 PM
Import data into seperate columns naulerich Excel Discussion (Misc queries) 32 April 4th 06 09:22 PM
Vlook up for matching data in two seperate sheets funky via OfficeKB.com Excel Discussion (Misc queries) 1 June 3rd 05 10:16 PM


All times are GMT +1. The time now is 08:15 AM.

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"