将单行复制到另一张表 VBA EXCEL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45231135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:53:22  来源:igfitidea点击:

Copy Single Row To Another Sheet VBA EXCEL

excelvbaexcel-vba

提问by Hyman

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.

我不知道为什么我在这方面最难熬。我只是想将 sheet1 中的一行复制到 sheet2 上的下一个可用行。我必须行复制,但它不会粘贴而不给我错误。这是我的副本,它正在工作。

ws1.Rows(j).EntireRow.Copy

回答by Mrig

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

回答by Anthony

Try this:

尝试这个:

Code Sample:

代码示例:

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

回答by nishit dey

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