I have 2 Excel file with same format but one is Master file (for calculating) and one file is extracted data from system. I want to copy extracted file’s data to Master file with VBA but it didn’t work.
File format looks like below:
So I want to Copy from A1 to I200 and then Paste it to Master file but it raised error “To do this, all the merged cells need to be the same size” or “PasteSpecial method of Range class failed”.
Below is my sample code:
Sub TransferData()
Dim main_wb As Workbook
Dim target_wb As Workbook
Application.ScreenUpdating = False
Set main_wb = Workbooks.Open("C:/Users/admin/Documents/Sample.xlsx")
main_sheet = "Sheet1"
Set target_wb = ThisWorkbook
target_sheet = "Sheet1"
main_wb.Sheets(main_sheet).Range("A1:I200").Copy
target_wb.Sheets(target_sheet).Range("A1").PasteSpecial xlPasteValues
Application.ScreenUpdating = True
End Sub
What should I do to copy merged cells? Thank you.