Find and loop through rows

LibbyB

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??

ricardogerbaudo

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related