![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Arizona
Posts: 72
|
I found some good code to hide rows if a value is present in Column E of that row (which either contains "Hide" or "0"), but it's a loop and for 4200 rows it takes 10 minutes to work through. Any suggestions on how to speed this up?
I thought instead of evaluating each row and hiding, could I unhide all, evaluate each and select only, then hide all that had been selected? Anyone think this would be faster? What would that code look like? Thanks. Here's what I'm using now: Private Sub Worksheet_Activate() ActiveSheet.Protect DrawingObjects:=False, Contents:=False, Scenarios:=False For Each c In Range("E1", Range("E4202").End(xlUp).Address) Select Case c.Value Case Is = "HIDE" c.EntireRow.Hidden = True Case Is = "0" c.EntireRow.Hidden = False End Select Next c ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True End Sub Thanks! |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Hi,
One of the simplest ways of speeding up such code is to turn off screen updating. I set up some sample data of 4200 rows and ran your macro. It took 15 seconds with screen updating turned on and 1 second with it turned off. Here is the modified code:- Code:
Private Sub Worksheet_Activate()
Dim c As Range, t As Single
'ActiveSheet.Protect DrawingObjects:=False, Contents:=False, Scenarios:=False
Application.ScreenUpdating = False
For Each c In Range("E1", Range("E4202").End(xlUp).Address)
Select Case c.Value
Case Is = "HIDE"
c.EntireRow.Hidden = True
Case Is = "0"
c.EntireRow.Hidden = False
End Select
Next c
Application.ScreenUpdating = True
'ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
HTH, Dan [ This Message was edited by: dk on 2002-05-10 10:25 ] |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Something like this takes less than a second to run for 40 rows. It uses the "Find" method and no loops.
I did this just for the cells that had the value "Hide" written in them. I couldn't see the point of this:
If all of the rows are visible in the first place. HTH |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Arizona
Posts: 72
|
The autofilter works best. I didn't think about putting it into the code. Thanks!
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Arizona
Posts: 72
|
Thanks Mark.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|