Jack
Jack

Reputation: 275

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

Upvotes: 3

Views: 77897

Answers (3)

Mrig
Mrig

Reputation: 11712

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

Upvotes: 11

nishit dey
nishit dey

Reputation: 458

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

Upvotes: 1

Anthony
Anthony

Reputation: 552

Try this:

Code Sample:

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

Upvotes: 1

Related Questions