Excel VBA - 使用变量粘贴代码后取消选择范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42769259/
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
Excel VBA - unselect range after paste with code using variables
提问by messi1335
I wrote a macro to filter, copy and paste the filtered criteria into different workbooks. I cannot figure out how to unselect the range that is being pasted in within the workbooks. I have tried ".range("A1").select" , "application.cutcopymode = false". I do not know what else to try..here is my code - any insight would be helpful
我编写了一个宏来过滤、复制和粘贴过滤条件到不同的工作簿中。我不知道如何取消选择在工作簿中粘贴的范围。我试过 ".range("A1").select" , "application.cutcopymode = false"。我不知道还能尝试什么……这是我的代码 - 任何见解都会有所帮助
Dim i As Long
Dim market As Variant, arrbooks() As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheet1.AutoFilterMode = False
market = Array(...
ReDim arrbooks(0 To UBound(market))
'create workbooks
For i = 0 To UBound(market)
Set arrbooks(i) = Workbooks.Add
Next
'retrieve data by autofilter
With Sheet4
For i = 0 To UBound(market)
.Range("H:H").AutoFilter field:=1, Criteria1:=market(i)
.Range("H1").CurrentRegion.SpecialCells(xlCellTypeVisible).Copy
Workbooks(arrbooks(i).Name).Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteAll
**workbooks(arrbooks(i).name).sheets(1).application.cutcopymode = false**
Next
End With
'save workbooks
For i = 0 To UBound(market)
**workbooks(arrbooks(i).name).sheets(1).application.cutcopymode = false**
Workbooks(arrbooks(i).Name).SaveAs "insert save path"
Workbooks(arrbooks(i).Name).Close
Next
'clean up
Application.ScreenUpdating = False
Sheet4.ShowAllData
Sheet4.AutoFilterMode = False
Application.DisplayAlerts = True
Sheet4.Activate
Sheet4.Range("A1").Select
due to compliance issues I cannot disclose the names I am filtering on
由于合规问题,我不能透露我正在过滤的名称
Thanks!
谢谢!
edit: **indicates where I tried inserting .application.cutcopymode = false
编辑:**表示我尝试插入 .application.cutcopymode = false 的位置
采纳答案by A.S.H
Ok I see now what you're trying to do. It has to do with the selection in the destination, not with the CutCopyMode
. Try
好的,我现在明白你要做什么了。它与目的地中的选择有关,而不是与CutCopyMode
. 尝试
Application.Goto workbooks(arrbooks(i).name).sheets(1).Range("A1")
OTOH, CutCopyMode
removes the "dotted" selection of the source, so that you cannot manually paste it again.
OTOH,CutCopyMode
删除了“点”选择源,这样就不能再次手动粘贴。
回答by victor
see this, Unselect column after pasting datai ended up selecting "A1" inorder to remove the merquri from selection area
看到这个,在粘贴数据后取消选择列我最终选择了“A1”以便从选择区域中删除merquri