【发布时间】:2022-08-18 15:45:31
【问题描述】:
你能帮我解决以下问题吗? 我有一个代码可以在特定位置打开一个 excel 文件并在其中进行过滤,但在此之后我无法选择我需要的范围:
Private Sub CommandButton1_Click()
\'dim Wb as string
\'dim Newdata as string
Newdata = \"M:\\Finance\\REPORTING\\2022_08\\Hóközi FC\\GL.xlsx\"
Set Wb = Workbooks.Open(Newdata)
ThisWorkbook.RefreshAll
ActiveSheet.Range(\"A:AE\").AutoFilter Field:=30, Criteria1:=\"P2\"
Windows(\"GL.xlsx\").Activate
Range(\"A1\").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
End Sub
提前致谢
-
作为一种好的做法,最好在 VBA 中避免使用
Select和Activate。您可能会发现 this post 很有用。此外,当提及Range时,您应该使用Wb.Range或ThisWorkbook.Range以避免任何混淆。