I am having some difficulties with a piece of code where I try to copy some data from an open workbook with name ("petros20190118.xlsm") to the workbook where I run the macro (Thisworkbook).
The cell C4 contains the string "20190118".
The error I am getting is "Run-time error '9': Subscript out of range" at row "Set x = Workbooks("petros" & filedate & ".xlsm")"
Sub Copy_Paste()
Dim x As Workbook
Dim filedate As String
filedate = ThisWorkbook.Sheets("Instructions").Range("C4")
ThisWorkbook.Sheets("Sheet0").Range("A2:V1000").ClearContents
Set x = Workbooks("petros" & filedate & ".xlsm")
x.Sheets("Sheet5").Range("A2:V1000").Copy
ThisWorkbook.Sheets("Sheet1").Range("A2").PasteSpecial xlPasteValues
x.Sheets("Sheet2").Range("A:S").Copy
ThisWorkbook.Sheets("Sheet3").Range("A:S").PasteSpecial xlPasteValues
End Sub
{}
button in the menu. – MBB70Shift ~
) – MBB70Sheet0
). – MBB70Copy/Paste
to move range data around. Setting ranges equal to each other is the more efficient approach from a memory perspective. – MBB70