![](/img/trans.png)
[英]VBA Match Cell Range to Worksheet Name and copy/paste to respective worksheet
[英]vba copy range to cell in new worksheet
我在同一工作簿中有两张正在处理的工作表。 我为每个变量定义了db
和rs
。
此处的目标是将db
的某一行(假设它符合我的条件)复制到rs
上的下一个空行 。
我试过了:
db.Range(db.Cells(i, 1), db.Cells(i, M)).Copy _ Destination:=rs.Cells(N, 1).End(xlUp).Offset(1, 0)
和
Set resrow = db.Range(db.Cells(i, 1), db.Cells(i, M)) 'next line is completely wrong inside the Range bracket rs.Range(rs.Cells(N, 1).End(xlUp).Offset(1, 0)).Resize(1, M).Value = resrow.Value
请注意, i
和M
是integers
。
我似乎在尝试为单元格设置范围值。 我怎样才能最好地解决它?
提前致谢
我认为您正在混合范围与单元格,我会尝试类似:
rsLastRow = rs.UsedRange.Rows.Count
db.Range(Cells(i, 1), Cells(i, M)).Copy
rs.Range("A" & rsLastRow).PasteSpecial Paste:=xlPasteValues
避免复制和粘贴以减少内存使用并提高VBA性能
Set rng1 = db.Cells(Rows.Count, "A").End(xlUp)
Set rn2 = db.UsedRange
col = rn2.Columns.Count
For Each cel In db.Range("A2:A" & rng1.Row)
if (condition) then
Set rng2 = rs.Cells(Rows.Count, "A").End(xlUp)
rs.Range(Cells(rng2.row, 1), Cells(rng2.row, col)).Value = db.Range(cells(cel.row,1),Cells(cel.row,col)).Value
end if
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.