Next without For..?

M

merry_fay

Hi,

I've written this bit of basic code to hide some rows for me:

Sub hiddenrow()

Range("A1").Select

For i = 1 To 516
ActiveCell.Offset(1, 0).Select
If ActiveCell.Value = "hiddenrow" Then
Selection.EntireRow.Hidden = True
Else

Next i

End Sub

but when I try to run it it, it comes up with the Compile Error 'Next
without For'
I've used For & I can't see what I've done wrong! Can anyone help please?

Thanks
merry_fay
 
J

Jacob Skaria

Every IF statement would need a End If Statement which is missing in your
code..

Sub hiddenrow()

Range("A1").Select

For i = 1 To 516
ActiveCell.Offset(1, 0).Select
If ActiveCell.Value = "hiddenrow" Then
Selection.EntireRow.Hidden = True
Else
'somthing
End If
Next i

End Sub
 
D

Dana DeLouis

merry_fay said:
Thankyou -I must have beeen having a really blond 5 mins!!


Just an idea...

Sub hiddenrow()
Dim R As Long
Const s As String = "hiddenrow"

For R = 1 To 516
Rows(R).Hidden = Cells(R, 1).Value = s
Next R
End Sub

HTH
Dana DeLouis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top