Reputation: 869
I'm trying to loop throw rows and say "if the cell in this column begins with 49, hide the entire row". Here's my code:
For i = 2 To LastRow
If Rows("AK" & i).Value Like "49*" Then
Rows("AK" & i).EntireRow.Hidden = True
Next i
It keeps stopping on the last line and saying "For without next". Can it not see the FOR line three lines up? This is just one of many statements I have like this but I think fixing this one will help me format the others. What am I doing wrong?
Upvotes: 2
Views: 24275
Reputation: 175986
Your missing an End If
(The wording is like that because It sees a Next
within an If
block without a matching For
; which is illegal)
For i = 2 To LastRow
If Range("AK" & i).Value Like "49*" Then
Range("AK" & i).EntireRow.Hidden = True
End If
Next i
Upvotes: 6
Reputation: 25272
End if is missing !
It is required if you put the next instruction on another line.
Upvotes: 2