I am writing a code to copy paste data from one workbook to another workbook
I am getting an error "PasteSpecial method of Range class failed " op on clicking debug and F5 the code runs without any issues
And I have used Application.displayalerts = false,but still I am getting the error and code runs if I try to press F5
S_xlobj.Activate
S_wsObj.Select
S_wsObj.Range(ThisWorkbook.Sheets("Config").Cells(i, 3) & F1_startRow & ":" & ThisWorkbook.Sheets("Config").Cells(i, 3) & F1_Lastrow).Copy
D_xlobj.Activate
D_wsObj.Select
D_wsObj.Range(Split(Cells(1, j).Address, "$")(1) & 2).PasteSpecial xlPasteValues
I expect it should run without errors. Sometimes it runs without any error but some times I am getting this error
Select
and specify a worksheet for everyCells
object! Excel cannot know in which sheetCells(1, j).Address
is if you don't specify one. Also please tell what the result ofDebug.Print Cells(1, j).Address
is after you specified it's worksheet. • Read and apply How to avoid using Select in Excel VBA. – PᴇʜRange(Split(Cells(1, j).Address, "$")(1) & 2)
is equivalent withCells(2, j)
. – AcsErno