I've got multiple excel files (.xlsm), which I would like to consolidate into 1 different workbook (just specific range). The range will be always the same, which means that I need to loop through the files in specific folder / folders and copy the range and paste as values into the new workbook.
I've written a script, which I thought that could work, but it does not. It gives me an error message:
Could you advise me what's wrong, please? It gives me the error on this line
x = Sheets("DBC PGB Review").Range("B3:E3").Copy
Or am I completely on a wrong way?
Sub LoopDBCs()
Dim myfolder As String
Dim myfile As String
Dim wb As Workbook, ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Sheets("DBCs")
Dim i As Integer
Dim x As Integer
Dim y As Integer
LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
myfolder = "F:\REQUIREMENTS\EXCEL\Retrieve DBC Data\DBCs\"
myfile = Dir(myfolder & "*.xlsm")
i = 2
Do While myfile <> ""
Workbooks.Open Filename:=myfolder & myfile, UpdateLinks:=0
x = Sheets("DBC PGB Review").Range("B3:E3").Copy
ActiveWorkbook.Close savechanges:=False
ws.Activate
ws.Range("A:D" & LastRow + 1).PasteSpecial xlPasteValues
i = i + 1
myfile = Dir
Loop
End Sub
Many thanks!