Takes To Long to Run this Macro

judgejustin

Board Regular
Joined
Mar 3, 2014
Messages
139
I need help to see if I have made this more complex than it needs to be. I need it to hide all rows that don't meet a certain criteria, code should be self explanitory. However it takes over a minute to run everytime I open this tab. Any suggestions?
Code:
Private Sub Worksheet_Activate()

With Sheets("Void List")

Dim i As Integer

For i = 2502 To 4 Step -1

Rows(i).Hidden = True

If Range("B" & i) = "VOID" Then

Rows(i).Hidden = False

If Range("B" & i) = "" Then

Rows(i).Hidden = True

If Range("B" & i) = "ACTIVE" Then

Rows(i).Hidden = True

If Range("B" & i) = "RESERVE" Then

Rows(i).Hidden = True

End If

End If

End If

End If

Next i

End With

End Sub
[/CODE}
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
If you have a header row on row 3, how about
VBA Code:
Private Sub Worksheet_Activate()

   Me.AutoFilterMode = False
   Me.Range("A3").AutoFilter 2, "Void"
End Sub
 
Upvote 0
Would this go into my current code somewhere?
If not then I'm not understanding how this would hide the rows that do not have void in them.
 
Upvote 0
It replaces all your code.
 
Upvote 0
WOW!
I've never used this before. I have had to teach myself how to do macros. This is so awesome, thank you!!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Quick question, this gives a drop down sort box in a completely different cell. It is a merged Cell of B1:G1. Is there a way to remove that?
Also, I modified the code so everything was reading from Column one. I placed the header I needed in A2, just in case that made some difference.

Code:
Private Sub Worksheet_Activate()

Me.AutoFilterMode = False

Me.Range("A2").AutoFilter 1, "Void"

End Sub
 
Upvote 0
Firstly, merged cells are an abomination & should be avoided like the plague.
If you are getting the filter in row 1, it suggests that you have cells in row 1 merged with cells in row2
 
Upvote 0

Forum statistics

Threads
1,214,378
Messages
6,119,188
Members
448,873
Latest member
jacksonashleigh99

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