Hello Guys,
I'm running a macro whose purpose is to copy certain ranges over to another worksheet. This used to work flawlessly in Excel 2007/2010, but for some reason it's giving me 'runtime error 1004' in 2013/2016. What's interesting is that part of the same code is executed just fine up until the last two bits of it.
I'm virtually clueless and would appreciate if someone could look and explain what's wrong with it.
Here's my code:
Problem occurs with the last two ranges (T:T & AK:AY), if I remove this bit of code, the rest runs just fine.
Thanks in advance for any advice!
I'm running a macro whose purpose is to copy certain ranges over to another worksheet. This used to work flawlessly in Excel 2007/2010, but for some reason it's giving me 'runtime error 1004' in 2013/2016. What's interesting is that part of the same code is executed just fine up until the last two bits of it.
I'm virtually clueless and would appreciate if someone could look and explain what's wrong with it.
Here's my code:
Code:
Sub copyRange()
Application.ScreenUpdating = False
Set srcSh = ActiveWorkbook.Worksheets("Source")
Set trgSh = ActiveWorkbook.Worksheets("Target")
Dim cont As Range
Dim start As Long
start = 2
For Each cont In srcSh.Range("BA3:BA500")
If cont = "Yes" Then
srcSh.Range(Cells(cont.Row, "J"), Cells(cont.Row, "J")).Copy
trgSh.Range("A" & start).PasteSpecial Paste:=xlPasteAll
srcSh.Range(Cells(cont.Row, "K"), Cells(cont.Row, "P")).Copy
trgSh.Range("B" & start).PasteSpecial Paste:=xlPasteValues
srcSh.Range(Cells(cont.Row, "T"), Cells(cont.Row, "T")).Copy
trgSh.Range("H" & start).PasteSpecial Paste:=xlPasteValues
srcSh.Range(Cells(cont.Row, "AK"), Cells(cont.Row, "AY")).Copy
trgSh.Range("I" & start).PasteSpecial Paste:=xlPasteValues
start = start + 1
End If
Next cont
End Sub
Problem occurs with the last two ranges (T:T & AK:AY), if I remove this bit of code, the rest runs just fine.
Thanks in advance for any advice!