Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default More Efficient code than this

Alok, your code works. Timings:-3000 rows 0.40.0, 6000 rows 0.26.9, 12000 rows
2:00.8, 20160 rows 2:00.9

Dana, I tried your code on 3,204 rows it takes 0:18:0 but at each repeat
processing
(ie I unhid the rows and ran again) the time increments by about 7secs. Just
curious why.

Tom, when I copied your code,"..Set rng= Sheet1.Cells(i,1) "E" .." turned
red. Did not proceed.

RobertR


"Dana DeLouis" wrote:

Here's are just some additional ideas...

Sub HideRows()
Dim Cell As Range
Const str_x As String = "x"

For Each Cell In Range("E5:E204").Cells
Cell.EntireRow.Hidden = (Cell = str_x) And (Cell(1, 4) = str_x)
Next
End Sub

Sub HideRows_v2()
Dim R As Long '(R)ow
Const str_x As String = "x"

For R = 5 To 204
Rows(R).Hidden = (Cells(R, 5) = str_x) And (Cells(R, 8) = str_x)
Next
End Sub


--
Dana DeLouis
Win XP & Office 2003


"thom hoyle" wrote in message
...
Here is a piece of code I'm using to hide rows that have an "x" in two of
the
columns. Is there a more efficient way to write this.

thanks

Sub HideRows()
Application.ScreenUpdating = False

Dim rng As Range
Dim i As Long

Set rng = Range("E5:E204")
i = 0 'set up a variable to see if range contains hidden rows

For Each c In rng
If c.EntireRow.Hidden = True Then
c.EntireRow.Hidden = False
i = 1
End If
Next

If i = 1 Then 'if any hidden rows unhide
Application.ScreenUpdating = True
Exit Sub
End If

For Each c In rng 'if no hidden rows unhidden then hide
If c.Value = "x" And c.Offset(0, 3).Value = "x" Then
c.EntireRow.Hidden = True
End If
Next
Application.ScreenUpdating = True
End Sub





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
making code more efficient timmulla Excel Discussion (Misc queries) 3 January 23rd 07 02:16 PM
Which is more efficient? Norm[_5_] Excel Programming 3 April 2nd 04 04:24 PM
Making code more efficient Tommi[_2_] Excel Programming 8 December 13th 03 07:47 PM
Book on how to write VBA code in a fast/efficient manner? J S Excel Programming 3 November 26th 03 02:12 PM
More efficient code Rob Bovey Excel Programming 1 July 9th 03 04:46 AM


All times are GMT +1. The time now is 03:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"