简体   繁体   中英

Copy Single Row To Another Sheet VBA EXCEL

I don't know why I am having the hardest time with this. I am just trying to copy a single row from sheet1 to the next available row on sheet2. I have to row copied but it just wont paste without giving me error. This is my copy and it is working.

ws1.Rows(j).EntireRow.Copy

Following should be helpful

Sub Demo()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim lastRow As Long, j As Long

    Set ws1 = ThisWorkbook.Sheets("Sheet1")
    Set ws2 = ThisWorkbook.Sheets("Sheet2")
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row

    For j = 1 To 10 'change loop as required
        If (your_condition) Then
            lastRow = lastRow + 1
            ws1.Rows(j).EntireRow.Copy ws2.Range("A" & lastRow)
        End If
    Next j
End Sub

Try this:

Code Sample:

Sheets("Sheet1").Cells(i, "A").EntireRow.Copy Destination:=Sheets("Sheet 2").Range("A" & Rows.Count).End(xlUp).Offset(1)

You may use the below code

Sub CopyPaste()
Sheet1.Range("A:A").Copy

Sheet2.Activate
col = 1
Do Until Sheet2.Cells(1, col) = ""
    col = col + 1
Loop

Sheet2.Cells(1, col).PasteSpecial xlPasteValues
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM