在我单击“全部”按钮一次以清除过滤器后在新工作表中显示所有数据后,新工作表没有显示。但是,当我单击“全部”按钮两次时,它仅显示整个数据。
这是我的代码:
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
答案 0 :(得分:2)
您可以尝试使用此代码,并告诉我您的问题是否已解决,我认为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