speed up this macro?

cmefly

Well-known Member
Joined
May 13, 2003
Messages
683
hi,

i've got a simple macro that is hiding rows based on a condition....but it takes almost an entire minute to run......any ideas on how to speed this up?

Private Sub Worksheet_Activate()
Dim x As Variant
Dim y As String
Dim i As Integer
Dim j As Integer
Dim b As String

Dim col As Integer

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual



col = 1

Rows("23:2806").Select
Selection.EntireRow.Hidden = False
Range("A24").Select

For i = 24 To 1200

y = Range("a" & i).Value

x = Application.VLookup(y, Sheets("hidden1").Range("a1:b22"), col, 0)

If IsError(x) Then
Rows(i).EntireRow.Hidden = True
End If

b = Range("O" & i).Value

If IsEmpty("O" & i) Then
Rows(i).EntireRow.Hidden = False
End If

If b = "Hide" Then
Rows(i).EntireRow.Hidden = True
End If
Next i

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
end sub



thank you in advance.

cmefly
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
What version of Excel are you running?

PS: Please post code on the Board within
Code:
 tags. Thanks.
 
Upvote 0
To me, I can be wrong, it seems that this whole bunch of code and loop should have just been an Advanced filter case.
 
Upvote 0
I meant to put both messages together wigi..

thanks for you help...i'll try to implement it.
 
Upvote 0
I can advice the advanced filter, since it allows to filter and bring up records that match the criteria. The criteria could be listed as you have now: cells a1:b22 on sheet hidden1. The other conditions should also be taken up in the criteria range, I think it should be possible.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top