iT邦幫忙

0

VBA command button 運行很慢

  • 分享至 

  • xImage

我的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
blanksoul12 iT邦研究生 5 級 ‧ 2021-12-24 12:16:32 檢舉
command button 只是一個促發點,按完也是行 code 的吧,沒分別.
ribbon 我唔清楚
https://ithelp.ithome.com.tw/questions/10201418 看看這個把會有幫助嗎?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答