• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using VBA find all values in a column and hide the row value found in with 2 rows above

ShellyTTC

New Member
I was able to create a macro on how to find the value in a cell and then hide that row with 2 rows above but my problem is continuing to do it until all values are found with the rows hidden. How will a loop know when to stop. I was able to use a do - loop for find and then the formula to place the value "yes" in an adjacent cell using the first find address. But when you are hiding rows it will not find that address now.

I know I have got to be close but I guess I've been working on this too long!!! Can someone please help me figure out how to make the code below work so that it does the following for each "yes" found? I am leaving the Do - loop stuff out in case you have a better/easier way to do this. Thank you so much in advance!

Code:
'
  ActiveCell.Offset(-1, 0).Range("A1").Select
  Cells.Find(What:="yes", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
  xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
  , SearchFormat:=False).Activate
  ActiveCell.Offset(-1, 0).Rows("1:2").EntireRow.Select
  ActiveCell.Activate
  Selection.EntireRow.Hidden = True
  ActiveCell.Offset(1, 0).Range("A1").Select

Shelly
 
Last edited by a moderator:
take an example
Code:
With Worksheets(1).Range("a1:a500")    
    Set c = .Find(2, lookin:=xlValues)
    If Not c Is Nothing Then        
           firstAddress = c.Address        
           Do
                 c.Value = 5            
                Set c = .FindNext(c)
           Loop While Not c Is Nothing And c.Address <> firstAddress    
    End If
End With
 
Thank you wudixin96. while waiting for a possible solution I came up with one but not as efficient as yours so I'll give that a try. Thanks again for your response!
 
Back
Top