Excel VBA - 将行复制到不同列中的新 Sheet

Excel VBA - Copy Rows to new Sheet in different column

我正在使用以下 VBA 在特定条件下将行从一个 Sheet 复制到另一个。我现在有一个新的 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

您不能将整行的副本粘贴到少于整行的目标位置。只复制数据并粘贴到目标的左上角单元格。

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