Home > Net >  Find and loop through rows
Find and loop through rows

Time:08-15

In my spreadsheet, in the first column one row contains a "!". I need to:

  1. find the cell which contains !
  2. loop through that row
  3. if the cell in the row starts with the letter G, clear the contents.
sub looprow()

Cells.Find(what:="!").Activate

for i = 1 to ActiveCell.End(xlToRight).Column
If left(Range(ActiveCell.Offset(0,i)).Value, 1) = 'G' Then 
       Range(ActiveCell.Offset(0,i)).ClearContents
       Next
end sub

Clearly this doesn't work but as I'm new to vba not sure how to fix this, how do I loop through the row??

CodePudding user response:

Try this:

Sub LoopRow()

    Cells.Find(what:="!").Activate

    For Each r In Range(ActiveCell, ActiveCell.End(xlToRight))
        If Left(r.Value, 1) = "G" Then
           r.ClearContents
        End If
    Next r
    
End Sub
  • Related