excel - 在 VBA 中清除另一个工作表中的过滤器后,将数据复制并粘贴到新工作表中
问题描述
清除过滤器后,单击“全部”按钮一次以显示新工作表中的所有数据后,新工作表未显示全部数据。但是,当我单击“全部”按钮两次时,它只会显示整个数据。
这是我的代码:
Sub Reset1_button()
Application.ScreenUpdating = False
Dim LastRow As Long
Dim LRow As Long
LastRow = WorksheetFunction.Max(Sheets("SALES").Cells(Rows.Count, "A").End(xlUp).Row, 2)
LastRow = LastRow + 1
LRow = WorksheetFunction.Max(Sheets("ONE_ALLIANZ_REPORT").Cells(Rows.Count, "A").End(xlUp).Row, 18)
LRow = LRow + 1
Range("A19:AQ" & LRow).Clear
Sheets("SALES").Select
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
Sheets("SALES").Select
ActiveSheet.Range("A3:AQ" & LastRow).Copy
Sheets("ONE_ALLIANZ_REPORT").Select
ActiveSheet.Range("A19").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.Select
End Sub
解决方案
您可以尝试使用此代码并告诉我您的问题是否已解决,我认为这select
就是问题所在。
另请注意,Thisworkbook
指定宏编码的工作簿
Sub Reset1_button()
Application.ScreenUpdating = False
Dim LastRow As Long
Dim LRow As Long
LastRow = WorksheetFunction.Max(ThisWorkbook.Sheets("SALES").Cells(Rows.Count, "A").End(xlUp).Row, 2)
LastRow = LastRow + 1
LRow = WorksheetFunction.Max(ThisWorkbook.Sheets("ONE_ALLIANZ_REPORT").Cells(Rows.Count, "A").End(xlUp).Row, 18)
LRow = LRow + 1
Range("A19:AQ" & LRow).Clear
If ThisWorkbook.Sheets("SALES").FilterMode Then
ThisWorkbook.Sheets("SALES").ShowAllData
End If
ThisWorkbook.Sheets("SALES").Range("A3:AQ" & LastRow).Copy Destination:=ThisWorkbook.Sheets("ONE_ALLIANZ_REPORT").Range("A19")
End Sub
推荐阅读
- android - 在颤振的 Mapbox 地图上添加标记(Mapbox GL)
- azure - 是否可以在 Azure Devops 管道中将模板作为 stepList 参数传递?
- http - 服务器总是返回“404 page not found”和“Client sent an HTTP request to an HTTPS server”。错误
- laravel - MethodNotAllwedException 405 拉瓦尔 5.5.*
- python - venv 在 powershell 中使用错误的解释器
- javascript - 随机化以在反应中为不同的站点访问者均匀呈现元素
- laravel - 如何为桌面和移动视图动态定义视图文件夹
- postgresql - 根据 Postgresql 表上的字段创建字母数字序列
- json - onesignal API,邮递员:找不到 app_id
- c - 如何使用信号在进程之间进行同步?