Search code examples
vbaexcelexcel-2013

Excel VBA - Next Row error on Activated Sheet


I have an Excel 2013 workbook.

I was utilising this SO Answer for Copy and find next blank Row

My code is

Sub Save()
    Dim NextRow As Range
    Set CopyZone = Worksheets("Sheet1").Range("A2:AO289")
    Set ToDataSheet = Worksheets("_data")
    Set NextRow = Range("B" & ToDataSheet.UsedRange.Rows.Count + 1)
    CopyZone.Cut
    ToDataSheet.Activate
    NextRow.PasteSpecial Paste:=xlValues, Transpose:=False
    Application.CutCopyMode = False
    Set NextRow = Nothing
End Sub

Copyzone is the output from my first sheet which has the newly formatted data. I set DataSheet to my to data sheet ("_data"), however it goes into debug on the line.

NextRow.PasteSpecial Paste:=xlValues, Transpose:=False

How do I get it to complete a paste the cut data into the to sheet on the next blank line?


Solution

  • Hope the below code solves your problem

    Sub Save()
        Set CopyZone = Worksheets("Sheet1").Range("A2:AO289")
        Set ToDataSheet = Worksheets("_data")
        CopyZone.Cut Destination:=ToDataSheet.Range("B" & ToDataSheet.UsedRange.Rows.Count + 1)
    End Sub