Hey All,
Just need a little help with some FSO stuff... Im trying to import some data from some files into a folder but it either doesnt copy the data or i just a rubbish result file...
Ive got a feeeling i keep mucking up this line here: wbS.Sheets("Sheet1").Cells((LastRow), 1).PasteSpecial any advice would be amazing ... once i get this working i can do the other years very very quickly
Cheers
Just need a little help with some FSO stuff... Im trying to import some data from some files into a folder but it either doesnt copy the data or i just a rubbish result file...
Code:
Sub filefinder()
Dim fs As New FileSystemObject
Dim f As File
Dim fld As Folder
Dim LastRow1 As Integer
Dim LastRow As Integer
Dim wbS As Workbook 'The summary workbook
Dim wbR As Workbook 'The other workbooks will use this reference
Dim i As Integer 'Keep track of rows
Set wbS = Application.Workbooks.Add()
Set fld = fs.GetFolder("Q:\Past Data\2005")
LastRow = 1
i = 0
For Each f In fld.Files ' Each file
Set wbR = Application.Workbooks.Open(f.Path)
wbR.Sheets("Sheet1").Activate
With ActiveSheet
LastRow1 = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
'Copy the first range
wbR.Sheets("Sheet1").Range(Cells(1, 1), Cells(LastRow1, 25)).Copy
'Paste the first range "as row". The range will be pasted from colum A to G
wbS.Sheets("Sheet1").Cells((LastRow), 1).PasteSpecial
'Close the file
Application.CutCopyMode = False
wbR.Close savechanges = False
LastRow = LastRow1
Set wbR = Nothing 'Set wbR to nothing and make it "ready" for the next file
Next f ' Next file
'Save the summary file
wbS.SaveAs ("Q:\Past Data\2005\summary.xls")
End Sub
Ive got a feeeling i keep mucking up this line here: wbS.Sheets("Sheet1").Cells((LastRow), 1).PasteSpecial any advice would be amazing ... once i get this working i can do the other years very very quickly
Cheers