0
votes

I'm trying to copy from Sheet 1 (A1:C1) and paste a special value with offset and xlDown in Sheet 2 and place the respective results in Range (B3:D3).

Sheet 1
enter image description here

Sheet 4 - (Required output)
enter image description here

I'm getting a Run-time error '1004' Application-defined or object-defined error.

Sub test()

Workbooks("testing.xlsm").Activate
Sheet1.Select
Range("A1:C1").Copy

Sheet2.Select
Range("B3").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

Application.OnTime Now + TimeValue("00:00:10"), "test"
End Sub
1
If you're trying to find the last cell, End(xlDown) is unreliable. See this approach.BigBen

1 Answers

0
votes

This should work:

Sub test()
Dim wsT As Worksheet
With Workbooks("testing.xlsm")
  Set wsT = .Sheets("Sheet2")
  wsT.Cells(wsT.Rows.Count, "B").End(xlUp).Offset(1, 0).Resize(1, 3).Value = _
    .Sheets("Sheet1").Range("A1:C1").Value
  Application.OnTime Now + TimeValue("00:00:10"), "test"
End With
End Sub

It's more efficient version of your code.
However, if you prefer to keep your style, this is less efficient version:

Sub test()

Workbooks("testing.xlsm").Activate
Sheet1.Select
Range("A1:C1").Copy

Sheet2.Select
Cells(Sheet2.Rows.Count, "B").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

Application.OnTime Now + TimeValue("00:00:10"), "test"
End Sub