I have been using the code below just fine for the past few months. But i have just discovered that because i am selecting a dynamic range in a worksheet, if i am not IN the worksheet, i get select method range class failed.
The below code fails:
With w.Sheets("Sheet1")
n = .Cells(Rows.Count, 2).End(xlUp).Row
.Range("Y2:AI2").Copy
.Cells(n, 25).Select
.Range(Selection, Selection.End(xlUp).Offset(1, 0)).PasteSpecial xlPasteFormulas
.Application.CutCopyMode = False
End With
The following code succeeds:
With w.Sheets("Sheet1")
n = .Cells(Rows.Count, 2).End(xlUp).Row
.Range("Y2:AI2").Copy
Sheets("Sheet1").Select
.Cells(n, 25).Select
.Range(Selection, Selection.End(xlUp).Offset(1, 0)).PasteSpecial xlPasteFormulas
.Application.CutCopyMode = False
End With
I have to select the sheet again. Ideally i want to avoid selecting/activating altogether!
Any steer in the right direction will be greatly appreciated!