I'm extremely new with VBA and am learning as I go, please bear with me.
I'm trying to copy data ranges from multiple Excel files in a folder into one single consolidator. Currently in each file is an identifier of the report submitter, which I am trying to copy into a range (A3:A-lastrow). Running into errors when I reach that point.
Update 1 - Some of you have pointed out my first error - including quotes on my lastrow variable. Thank you! Have removed them but now the macro doesn't seem to be able to copy paste between my source file and destination file. Is there something wrong with how I declared the workbook variables or is it the way I am calling them?
Update 2 - After going through @Mikku answer and adjusting it a bit I'm able to safely say that the code finally works!
Sub MainCopy()
Dim SrcBk As Workbook
Dim FSO As Object
Dim Folder As Object
Dim SrcF As Object
Dim F1 As Object
Dim ws As Worksheet
Dim lastrow As Long
Dim DestWk As Worksheet
Set DestWk = ThisWorkbook.Sheets("Output")
'Define source folder
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.Getfolder(ActiveWorkbook.Sheets("Cover").Range("F5"))
Set SrcF = Folder.Files
'Loop files in Directory
For Each F1 In SrcF
lastrow = DestWk.Cells(DestWk.Rows.Count, "B").End(xlUp).Row
ThisWorkbook.Sheets("Reference").Select
ThisWorkbook.Sheets("Reference").Range("A3:C113").Select
Selection.Copy
Worksheets("Output").Select
Range("B" & lastrow + 1).PasteSpecial xlValues
Set SrcBk = Workbooks.Open(F1)
Worksheets("Cover").Select
Range("K1").Copy
DestWk.Range("A" & DestWk.Cells(DestWk.Rows.Count, "A").End(xlUp).Row & ":" & "A" & lastrow).PasteSpecial Paste:=xlPasteValues
SrcBk.Worksheet("Data").Range("C7:I38").Copy
DestWk.Cells("E" & lastrow).PasteSpecial Paste:=xlPasteValues
lastrow = DestWk.Cells(DestWk.Rows.Count, "I").End(xlUp).Row
SrcBk.Worksheet("Data").Range("C40:I68").Copy
DestWk.Cells("E" & lastrow).PasteSpecial Paste:=xlPasteValues
lastrow = DestWk.Cells(DestWk.Rows.Count, "I").End(xlUp).Row
SrcBk.Worksheet("Performance").Range("C8:I61").Copy
DestWk.Cells("E" & lastrow).PasteSpecial Paste:=xlPasteValues
SrcBk.Close
Next F1
End Sub