Excel VBA-将行复制到其他列中的新工作表 [英] Excel VBA - Copy Rows to new Sheet in different column
本文介绍了Excel VBA-将行复制到其他列中的新工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下VBA在特定条件下将行从一张纸复制到另一张纸。我现在有一个新的Excel,可以在其中重复使用,但是这次我想在C5列而不是A5处开始粘贴。我知道您可以指定.cells,但这在这里无法像我想象的那么简单。
I am using the following VBA to copy under a certain condition the Rows from one Sheet to another. I've now a new Excel where I want to reuse this, however this time I would like to start the pasting at column C5 rather than A5. I know that you can specify .cells but this is not working here that simple as I had imagined.
任何帮助都会很棒:)
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
推荐答案
您不能将整行的副本粘贴到小于整行的目标中。仅复制数据并粘贴到目标的左上角单元格中。
You cannot paste a full row's copy into a destination that is less than a full row. Only copy what is data and paste into the top-left cell of the destination.
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
这篇关于Excel VBA-将行复制到其他列中的新工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文