[英]Excel VBA - Copy Rows to new Sheet in different column
我正在使用以下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
您不能將整行的副本粘貼到小於整行的目標中。 僅復制數據,然后粘貼到目標的左上角單元格中。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.