我的workshhet 有大槪30行, 11000列的資料
在vba運行以下code只需1.7秒,
但在command button 上就要超過2分鐘,在ribbon上的macro運行也是這樣長時間
請問有人遇過這種情况嗎,會不會是關data type事,或者本身excel檔的設置而導致?
把本身data 移到新的一個workbook會否有幫助?
我的code
Sub filter()
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim c1 As Variant, c2 As Variant, c3 As Variant
With ActiveSheet
FirstRow = .Range("A20").End(xlDown).Row
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
Set rngData = .Range("A" & FirstRow & ":A" & LastRow)
c1 = .Rows("3:3").Find(What:=xxx _
, LookAt:=xlWhole).Column
c2 = .Rows("3:3").Find(What:=xxx _
, LookAt:=xlWhole).Column
c3 = .Rows("3:3").Find(What:=xxx _
, LookAt:=xlWhole).Column
End With
With rngData
.AutoFilter Field:=c1, _
Criteria1:=xxxx
.AutoFilter Field:=c2, _
Criteria1:=Array(xxx), Operator:=xlFilterValues
End With
Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Select
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub