Right now I have a Workbook containing a master sheet and multiple individual customer sheets. I am writing some code to look at the customer column, copy the row and then paste it in their respective sheet. At the end I want the last row from my template sheet to be pasted as the last row for the customer sheet. This is to calculate averages. So far it works but the last row gets pasted to the top of the sheet but not the bottom. I cant figure out how to get it to be the last row.
Sub copyPasteDataCustomer()
Dim sws As Worksheet
Dim tws As Worksheet
Dim cel As Range
Set sws = Sheets("Master")
For Each cel In sws.Range("B5:B" & Range("B" & Rows.Count).End(xlUp).Row)
Set tws = Sheets(CStr(cel.Value))
cel.EntireRow.Copy tws.Range("A" & Rows.Count).End(xlUp).Offset(1)
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Canvus")
Dim ws2 As Worksheet: Set ws2 = tws
For i = 2 To ws1.Range("G" & Rows.Count).End(xlUp).Row
ws1.Rows(i).Copy ws2.Rows(ws2.Cells(ws2.Rows.Count, "G").End(xlUp))
Next i
Next cel
End Sub
For i
loop? You may also need to add.Row
after.End(xlUp)
in that loop to make sure it's getting the row properly. - BruceWayne...Copy ws2.Rows(ws2.Cells(ws2.Rows.Count, "G").End(xlUp).Row + 1)
. Also, why create another Worksheet variable, and not just usetws
instead ofws2
? - BruceWayneF8
and see if you can pinpoint where/why it's not just pasting one row to the end each time. - BruceWayne