Code overwriting data on paste problem

  • Looking for help to stop my macro overwriting manually entered data.

    The code below works - sort of. If there is data in column D, then the data will paste on the next empty row.

    However if there is data manually entered in any other column than D, then the code just overwrites that data when pasting.

    Could I have some help in modifying my code so that if it sees any data in any column, it will go to the next empty row and paste from column D as required by the existing code.


    Sub WagesAllocationL4()
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet
    Dim lr As Long
    Set pasteSheet = Worksheets("Fortnightly")
      lr = pasteSheet.Range("D" & Rows.Count).End(xlUp).Row
    pasteSheet.Range("D" & lr + 1).PasteSpecial xlValues
    Application.CutCopyMode = False
    End Sub
  • Instead of this:

    lr = pasteSheet.Range("D" & Rows.Count).End(xlUp).Row

    use this:

    lr = pasteSheet.Range("D1:K" & Rows.Count).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
  • Welcome to the Forum. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post

    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.

    How to use code tags

    Just highlight all of the code and press the <> in the post menu above button to add the code tags.


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!