[Solved] Count, insert row, paste in other tab [closed]


try the code below :

Sub test()

            Dim ws As Worksheet
            Dim ws2 As Worksheet

            Set ws = ThisWorkbook.Sheets("sheet1")
            Set ws2 = ThisWorkbook.Sheets("sheet2")

            lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
            lastRow2 = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row

            i = 1
            Do While ws.Cells(i, 1).Value = ws2.Cells(i, 1).Value
                 i = i + 1
            Loop

            For j = i To lastRow
                lastRow2 = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row
                ws2.Rows(lastRow2 + 1).EntireRow.Insert
                ws2.Range("A" & lastRow2 + 1).Value = ws.Range("A" & j).Value
            Next j

        End Sub

21

solved Count, insert row, paste in other tab [closed]