0

I have the below code where I need to make it work as below.

  1. copy from row 10 till last row with value.
  2. the last row will be with reference to column N starting from cell N10..

any suggestions from SO team?

    wbSource.Sheets(SITE_TEMPLATE).Rows(10).EntireRow.Copy wbMaster.Sheets(SITE_TEMPLATE).Range("A" & insertRow2)
    insertRow2 = insertRow2 + 1
BigBen
  • 46,229
  • 7
  • 24
  • 40
Raags
  • 35
  • 1
  • 7
  • Perhaps take a look at [this question](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba) for how to find the last row. – BigBen Mar 09 '20 at 13:45
  • @BigBen hi.. I referred the post. but I need start the search from row 10 with reference to another column. that is where Im stuck!! – Raags Mar 09 '20 at 13:50
  • That other post should help you do *exactly* that. – BigBen Mar 09 '20 at 13:52
  • You know how to find the last row, you did it for `insertRow2`. All you need to do is find and assign the last row for `Column N` to a variable, and modify `.Rows(10)` to `.Rows(10 & ":" & wbSourceLastRow)`, or what ever you want to name the variable – GMalc Mar 09 '20 at 14:39
  • @BigBen I came upto this. but its not copying till end row. ```lrow = wrSource.Cells.Find(What:="*", After:=wrSource.Range("N10"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row 'copying row 10 from sheet 2 with name "Site Creation Template(Project)" wbSource.Sheets(SITE_TEMPLATE).Rows(10 & ":" & lrow).EntireRow.Copy wbMaster.Sheets(SITE_TEMPLATE).Range("A" & insertRow2)``` – Raags Mar 09 '20 at 15:26

1 Answers1

0

Try this:

Sub test()

    Dim LastRow As Long

    With Workbooks("wbSource").Worksheets("SITE_TEMPLATE")

        LastRow = .Cells(.Rows.Count, "N").End(xlUp).Row

        .Rows(10 & ":" & LastRow).EntireRow.Copy wbMaster.Sheets(SITE_TEMPLATE).Range("A" & insertRow2)

        insertRow2 = insertRow2 + 1

    End With

End Sub
Error 1004
  • 7,877
  • 3
  • 23
  • 46