beartooth91
New Member
- Joined
- Dec 15, 2024
- Messages
- 46
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Hey Everyone -
I'm trying to copy data out of one workbook and append it to another workbook. Both workbooks have the same name but in different folders with different data. Renaming either one isn't an option.
I'm getting the 'application-defined or object-defined error' on the 'Set Destination....' line.
Any ideas on how to fix?
I'm trying to copy data out of one workbook and append it to another workbook. Both workbooks have the same name but in different folders with different data. Renaming either one isn't an option.
I'm getting the 'application-defined or object-defined error' on the 'Set Destination....' line.
Any ideas on how to fix?
VBA Code:
Sub Test_Copy_Same_Name()
Workbooks.Open Filename:=ThisWorkbook.Path & "/RTIME_Base" & "\" & "AIDESC.xlsx"
Dim lr As Long, myArray(), Destination As Range
With Workbooks("AIDESC.xlsx")
lr = Cells(Rows.Count, "E").End(xlUp).Row
myArray = Range("B2:AF" & lr)
End With
Workbooks("AIDESC.xlsx").Close SaveChanges:=False
Workbooks.Open Filename:=ThisWorkbook.Path & "/Bulk Update Sheets" & "\" & "AIDESC.xlsx"
With Workbooks("AIDESC.xlsx").Worksheets("Sheet1")
lr = .Range("E" & Rows.Count).End(xlUp).Row
Set Destination = .Range("C:AG" & lr)
Destination.Resize(UBound(myArray, 2), UBound(myArray, 1)).Value = Application.Transpose(myArray)
End With
End Sub