I need to open all Excel files that are in a folder, and copy every first, 57th, 72th, 73th and 74th row from each file into the same workbook.
This this is what I have so far:
Dim i As Integer
Dim wbOpen As Workbook
Dim MyPath As String
Dim strFilename As String
MyPath = "C:\foldername" 'the folder
strFilename = Dir(MyPath & "\*.xls") 'all excel files in folder
Do Until strFilename = ""
'here it gives an error, saying it can't open file,
' even though it apparently has found it
wbOpen = Workbooks.Open(strFilename)
'copy relevant text
Workbooks(2).Activate
Sheets("blad1").Rows(1, 57, 72, 73, 74).Copy
Workbooks(1).Activate
'select the first empty row
irow = ActiveSheet.UsedRange.Rows.Count + 1
'insert the copied
irow.Insert Shift:=xlDown
'close the workbook without saving
Workbooks(2).Close SaveChanges:=False
Close
Loop
Try it this way:
Tell me if this works
EDIT: Fix
Sheets("blad1").Rows(1, 57, 72, 73, 74).CopytoSheets("blad1").Rows("1, 57, 72, 73, 74").Copy