使用 VBA 在活动单元格中进行特殊粘贴
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42736628/
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
Paste Special in Active Cell using VBA
提问by Rosya Chairani
I want to copy a table (range A1 to AV3) from Worksheet 2 to Active Cell in Worksheet 1
我想将工作表 2 中的表格(范围 A1 到 AV3)复制到工作表 1 中的活动单元格
my current code is:
我目前的代码是:
Private Sub CommandButton1_Click()
Worksheets("Sheet2").Range("A1:AV3").Copy
Worksheets("Sheet1).ActiveCell.PasteSpecial Paste:=xlPasteFormats
Worksheets("Sheet1").ActiveCell.PasteSpecial Paste:=xlPasteValues
End Sub
can anyone help me to fix this? I want every time I click the button, it will copy to any active cell.
谁能帮我解决这个问题?我希望每次单击按钮时,它都会复制到任何活动单元格。
回答by Shai Rado
Assuming your ActiveCell
is in "Sheet1", and the Command-Button is also in "Sheet1", there's no need to add Worksheets("Sheet1")
before ActiveCell
, just use something like the code below:
假设您ActiveCell
在“Sheet1”中,并且命令按钮也在“Sheet1”中,则无需添加Worksheets("Sheet1")
before ActiveCell
,只需使用如下代码:
Private Sub CommandButton1_Click()
Worksheets("Sheet2").Range("A1:AV3").Copy
ActiveCell.PasteSpecial xlPasteFormats
ActiveCell.PasteSpecial xlPasteValues
End Sub