vba VBA中ctrl + shift + down的代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35559443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Code for ctrl + shift + down in VBA
提问by Moe
How can I possibly do a ctrl + shift + down on excel vba. I also wanted to know to then paste that as special values. The code i currently have is this
我怎么可能在 excel vba 上按 ctrl + shift + down。我也想知道然后将其粘贴为特殊值。我目前拥有的代码是这个
Sub CopyCol()
Sheets("Sheet1").Range("B2").End(xlDown).Select.Copy
Sheets("Sheet2").Range("B14").PasteSpecial xlPasteValues
End Sub
So what i am trying to do is copy everything in the B column but not the whole column itself. Like if the entries end at row 100 it should stop over there pretty much how ctrl+shift+end work like. Then copy whatever is in there and paste it as values in sheet2 at b14 because that is the specific location i need it at. I know that putting .select after (xldown) would help me do that but then it wont let me copy. Also pasting into the other sheet doesn't work either.
所以我想要做的是复制 B 列中的所有内容,而不是整个列本身。就像如果条目在第 100 行结束,它应该在那里停止,就像 ctrl+shift+end 一样。然后复制其中的任何内容并将其粘贴为 sheet2 中 b14 处的值,因为那是我需要它的特定位置。我知道将 .select 放在 (xldown) 之后会帮助我做到这一点,但它不会让我复制。粘贴到另一张纸上也不起作用。
回答by Scott Craner
The method you would use is this:
您将使用的方法是:
Sheets("Sheet1").Range(Sheets("Sheet1").Range("B2"),Sheets("Sheet1").Range("B2").End(xlDown)).Copy
The Range() object works like this Range(Start Cell, End Cell)
Range() 对象是这样工作的 Range(Start Cell, End Cell)
So you anchor the first cell with Sheets("Sheet1").Range("B2").
所以你用 锚定第一个单元格Sheets("Sheet1").Range("B2")。
And anchor the End Cell with Sheets("Sheet1").Range("B2").End(xlDown)).
并用 锚定 End Cell Sheets("Sheet1").Range("B2").End(xlDown))。
Now another method with less typing is to use the With block:
现在另一种减少输入的方法是使用 With 块:
With Sheets("Sheet1")
.Range(.Range("B2"),.Range("B2").End(xlDown)).Copy
End with

