I am writting a macro that is supposed to copy entire rows from a certain sheet ("Global_IB") to another sheet ("Interpolated Value") in the same Excel file. I need to copy and paste the information in order to exploit the data without having to touch anything in the original data base.
In the code below, I basically go ahead and find the last row of my data base: LR. I then proceed to copy the first three columns of "Global_IB" (without the title row), and paste them in "Interpolated Value) in rows A, B, and C. And so on for the other rows that I am interested in.
This code works perfectly well as long as "Global_IB" has a reasonable amount of rows.
When I try to use the entire file (52 000 rows), an error appears: "Copy Method of Class range failed".
I have read that it may have to do with the fact that excel is limiting the amount of rows it can copy at once to 2516, but funily enough it works for me when I use 3000 rows etc.
I would be interested to know if you have an idea what the problem is and how I could solve it. Maybe a loop that copies and pastes a limited number of rows at a time. If yes, how would you adapt the code ? I can't seem to do it right on my own.
Thank you very much for your help!
Private Sub copieIB()
Dim LR As Long
LR = Sheets("Global_IB").Cells(Rows.Count, 3).End(xlUp).Row
Application.Calculation = xlManual
'Copy in Interpolated Value
Sheets("Interpolated_Value").Range("A2").Resize(LR - 1, 3).Value = Sheets("Global_IB").Cells(2, 4).Resize(LR - 1, 3).Value
Sheets("Interpolated_Value").Range("D2").Resize(LR - 1, 1).Value = Sheets("Global_IB").Cells(2, 8).Resize(LR - 1, 1).Value
Sheets("Interpolated_Value").Range("E2").Resize(LR - 1, 1).Value = Sheets("Global_IB").Cells(2, 10).Resize(LR - 1, 1).Value
Sheets("Interpolated_Value").Range("F2").Resize(LR - 1, 1).Value = Sheets("Global_IB").Cells(2, 14).Resize(LR - 1, 1).Value
Sheets("Interpolated_Value").Range("G2").Resize(LR - 1, 1).Value = Sheets("Global_IB").Cells(2, 18).Resize(LR - 1, 1).Value
Application.Calculation = xlAutomatic
End Sub