In my spreadsheet, in the first column one row contains a "!". I need to:
- find the cell which contains !
- loop through that row
- 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