[英]Excel VBA - unselect range after paste with code using variables
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".
我试过“.range(”A1“)。选择”,“application.cutcopymode = false”。 I do not know what else to try..here is my code - any insight would be helpful
我不知道还有什么可以尝试......我的代码也是如此 - 任何见解都会有所帮助
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
Ok I see now what you're trying to do. 好的,我现在看到你想要做什么。 It has to do with the selection in the destination, not with the
CutCopyMode
. 它与目标中的选择有关,而与
CutCopyMode
。 Try 尝试
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
删除了源的“点”选择,因此您无法再次手动粘贴它。
看到这个, 粘贴数据后取消选择列我最终选择“A1”以从选择区域中删除merquri
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.