View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
CPower[_23_] CPower[_23_] is offline
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