Excel VBA-将行复制到其他列中的新工作表

时间:2018-08-17 09:20:03

标签: excel vba copy-paste

我正在使用以下VBA在特定条件下将行从一张纸复制到另一张纸。我现在有一个新的Excel,我想在其中重新使用它,但是这次我想在C5列而不是A5处开始粘贴。我知道您可以指定.cells,但这在这里无法像我想象的那么简单。

任何帮助都会很棒:)

Sub CopyRows()
Dim Zeile As Long
Dim ZeileMax As Long
Dim n As Long

Set RAW = Worksheets("RAWdata")
Set Closed = Worksheets("RAWclosed")

With RAW
ZeileMax = .UsedRange.Rows.Count
n = 5

For Zeile = 2 To ZeileMax

If .Cells(Zeile, 5).Value = "Closed" Then

.Rows(Zeile).Copy Destination:=Closed.Rows(n)
n = n + 1

End If
Next Zeile
End With
End Sub

1 个答案:

答案 0 :(得分:0)

您不能将整行的副本粘贴到小于整行的目标中。仅复制数据,然后粘贴到目标的左上角单元格中。

For Zeile = 2 To ZeileMax

    If .Cells(Zeile, 5).Value = "Closed" Then

        .Range(.cells(Zeile, "A"), .cells(Zeile, .columns.count).end(xltoleft)).Copy _
             Destination:=Closed.cells(n, "C")
        n = n + 1

    End If

Next Zeile
相关问题