简体   繁体   English

复制和粘贴多个范围

[英]Copy and paste multiple ranges

I need to select multiple ranges.我需要选择多个范围。

This is my code to select the first range, but now I need to edit this line to add the second range.这是我选择第一个范围的代码,但现在我需要编辑此行以添加第二个范围。

Range(ActiveCell.Offset(-1, -8), ActiveCell.Offset(-1, -2)).Select

Range("A:G,T:W") is what I'm trying to grab dynamically. Range("A:G,T:W") 是我试图动态抓取的。

Update: VincentG gave me code更新:VincentG 给了我代码

Intersect(ActiveCell.EntireRow, Range("A:G,T:W")).Copy

I've copied the range, but now I need to paste it in the row below, same columns.我已经复制了范围,但现在我需要将它粘贴到下一行的相同列中。 I tried to use the same code我尝试使用相同的代码

Intersect(ActiveCell.EntireRow, Range("A:G,T:W")).PasteSpecial (xlPasteValues)

to paste but it gives me the error粘贴但它给了我错误

"This action won't work on multiple selections" “此操作不适用于多项选择”

Your code is syntactically correct, but I suspect you aren't getting the expected result.您的代码在语法上是正确的,但我怀疑您没有得到预期的结果。 Further guessing: I guess you want to select A:G and T:W on the current row.进一步猜测:我猜您想在当前行上选择 A:G 和 T:W。 If that guess is correct, then try this:如果这个猜测是正确的,那么试试这个:

    Union( _
        Range(Cells(ActiveCell.Row, "A"), Cells(ActiveCell.Row, "G")), _
        Range(Cells(ActiveCell.Row, "T"), Cells(ActiveCell.Row, "W")) _
    ).Select

For anyone else looking at this post:对于看这篇文章的其他人:

I ended up copying the one section, pasting it where I needed it, then using activecell.offset, I chose the other range, copied and pasted.我最终复制了一个部分,将它粘贴到我需要的地方,然后使用 activecell.offset,我选择了另一个范围,复制并粘贴。 I never did find a way to copy and paste multiple ranges.我从来没有找到复制和粘贴多个范围的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM