Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default changing find to for/next


I have the below code which rins really slow and i think it would be
better as a for range = 1 to 500 and then using next

Please could someone help me adapt it to do just that

Basically it looks in column a between rows 1 to 500 and for each cell
that has a y value it hides that row



Sub AutoHidePlanRows()

Let Chk = "Y"

With Worksheets("Plan").Range("a1:a500")
Set c = .Find(Chk, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
'Hide cell here
Let MyAdd = c.Row
LetMyRow = MyAdd & ":" & MyAdd
Range(LetMyRow).Select
Selection.EntireRow.Hidden = True
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Sub


--
ceemo
------------------------------------------------------------------------
ceemo's Profile: http://www.excelforum.com/member.php...o&userid=10650
View this thread: http://www.excelforum.com/showthread...hreadid=545451

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default changing find to for/next


hi Ceemo,

I think a better approach would be to use an autofilter and filter fo
all rows that do not equal "y", the code only takes one line & use
Excel's inbuilt functionality which is often faster than other macr
approaches eg:

Selection.AutoFilter Field:=1, Criteria1:="<y"

where the one is the # of the column relative to the left of the are
that is being autofiltered.

btw, I think Ron Debruin has a good page on filtering for values - i
may pay to google it.

hth
Rob Brockett
NZ
Always learning & the best way to learn is to experience..

--
broro18
-----------------------------------------------------------------------
broro183's Profile: http://www.excelforum.com/member.php...fo&userid=3006
View this thread: http://www.excelforum.com/showthread.php?threadid=54545

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default changing find to for/next

I don't think your proposed solution would be quicker, in fact I would
expect it to be slower.

--
HTH

Bob Phillips

(replace somewhere in email address with googlemail if mailing direct)

"ceemo" wrote in
message ...

I have the below code which rins really slow and i think it would be
better as a for range = 1 to 500 and then using next

Please could someone help me adapt it to do just that

Basically it looks in column a between rows 1 to 500 and for each cell
that has a y value it hides that row



Sub AutoHidePlanRows()

Let Chk = "Y"

With Worksheets("Plan").Range("a1:a500")
Set c = .Find(Chk, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
'Hide cell here
Let MyAdd = c.Row
LetMyRow = MyAdd & ":" & MyAdd
Range(LetMyRow).Select
Selection.EntireRow.Hidden = True
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Sub


--
ceemo
------------------------------------------------------------------------
ceemo's Profile:

http://www.excelforum.com/member.php...o&userid=10650
View this thread: http://www.excelforum.com/showthread...hreadid=545451



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default changing find to for/next

Ceemo,

Try the macro below - it should be quicker.

HTH,
Bernie
MS Excel MVP

Sub CeemoHide()
Dim myR As Range
Dim myV As Range

Set myR = Range("A2", Range("A65536").End(xlUp))
myR.AutoFilter Field:=1, Criteria1:="Y"
Set myV = myR.SpecialCells(xlCellTypeVisible)
myR.AutoFilter
myV.EntireRow.Hidden = True
End Sub


"ceemo" wrote in message
...

I have the below code which rins really slow and i think it would be
better as a for range = 1 to 500 and then using next

Please could someone help me adapt it to do just that

Basically it looks in column a between rows 1 to 500 and for each cell
that has a y value it hides that row



Sub AutoHidePlanRows()

Let Chk = "Y"

With Worksheets("Plan").Range("a1:a500")
Set c = .Find(Chk, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
'Hide cell here
Let MyAdd = c.Row
LetMyRow = MyAdd & ":" & MyAdd
Range(LetMyRow).Select
Selection.EntireRow.Hidden = True
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Sub


--
ceemo
------------------------------------------------------------------------
ceemo's Profile: http://www.excelforum.com/member.php...o&userid=10650
View this thread: http://www.excelforum.com/showthread...hreadid=545451



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
Find and Replace - Changing 1st # only Studebaker Excel Discussion (Misc queries) 3 October 12th 07 01:12 AM
Find and Replace without changing font Tony Logan Excel Discussion (Misc queries) 4 December 11th 06 03:02 PM
Macro help on changing data in Edit Find Box Jim Excel Discussion (Misc queries) 3 November 7th 06 11:14 PM
Need to find oldest date in ever changing list. Alan Anderson via OfficeKB.com Excel Worksheet Functions 5 February 20th 05 04:09 AM
changing the constants in the find function OkieViking Excel Programming 2 July 1st 04 05:38 PM


All times are GMT +1. The time now is 02:10 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"