2

This macro is intended to via an Inputbox using Findstring, find a row, copy it to the first empty row of a different worksheet, and delete the row on the original worksheet.

If Not Rng Is Nothing Then
    Rng.EntireRow.Copy
    Worksheets("ScrapLogboek").Cells(Rows.Count, "A").End(xlUp).Offset(1, -1)
    Worksheets("ScrapLogboek").Range("A2").PasteSpecial
    Rng.EntireRow.Delete
Else
    MsgBox ("Niks gescrapt. Check of het B-nummer correct is.")
End If

End With
    MsgBox ("Logboek gescrapt.")
End If
End Sub

I get a syntax error on the Offset function.

Worksheets("ScrapLogboek").Cells(Rows.Count, "A").End(xlUp).Offset(1, -1).
5
  • 1
    Please add to your code example or tidy it up. You've got End With and End If with no starting condition. Which line is it failing on? What is wrong? Commented Dec 2, 2015 at 13:13
  • Excuse me Tom. Total code was too long, giving an error. I approved your edit. Line that it is failing on is; Worksheets("ScrapLogboek").Cells(Rows.Count, "A").End(xlUp).Offset(1, -1). It works perfectly without this, but keeps overwriting the data found, and copied to another worksheet. To prevent this from happening i wanted to try it with the Offset function. Commented Dec 2, 2015 at 13:15
  • 1
    You aren't doing anything with the offset. Don't you want to select it or assign it a value? Commented Dec 2, 2015 at 13:17
  • You're telling the offset to go 1 down on the Row and 1 to the left on the Column. As you're doing this in Column A there is no where for it to go giving you the error. Commented Dec 2, 2015 at 13:17
  • Tom, that was pretty stupid. Thank you for that correction. @Alex4336, i want the Pasting function below it to look for the first empty row and paste there, instead of pasting in A2 everytime, overwriting everything. Commented Dec 2, 2015 at 13:20

1 Answer 1

2

You are in column A, so you can't Offset minus one column because there is none other on the left!

Try your code with Worksheets("ScrapLogboek").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) and it'll work! ;)

And your code would always paste on A2 which is probably not the purpose, so here is the corrected version :

If Not Rng Is Nothing Then
    Rng.EntireRow.Copy
    Worksheets("ScrapLogboek").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
    Rng.EntireRow.Delete
Else
    MsgBox ("Niks gescrapt. Check of het B-nummer correct is.")
End If

End With
    MsgBox ("Logboek gescrapt.")
End If
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

You're my hero of the day! Thank you for teaching me how to handle the Offset, and even correcting my code. Bon Merci!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.