I’ve got some performance issues in my Excel Workbook.
I’ve got 2 different worksheets:
- the first sheet has got a lot of information
- the second sheet only shows what is useful (for someone who is not using it everyday).
On that second sheet I need to check if any rows are marked in the sorting function, and at the moment I do it this way in VBA:
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=1
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=2
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=3
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=4
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=5
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=6
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=7
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=8
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=9
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=10
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=11
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=12
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=13
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=14
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=15
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=16
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=17
ActiveSheet.Range("$A$12:$R$132").AutoFilter Field:=18
That takes too much time compared to the task I’m performing. I’m very new to VBA and I want to know if there is a more efficient way to do it.
If you just want to remove the autofilters, you can use:
If you want to remove the filters and put them back on after your function has run, it is more complicated.
When interacting with the sheets from VBA, make sure to use this to make your code run faster: