ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Next without For..? (https://www.excelbanter.com/excel-discussion-misc-queries/229210-next-without.html)

merry_fay

Next without For..?
 
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

Jacob Skaria

Next without For..?
 
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

--
If this post helps click Yes
---------------
Jacob Skaria


"merry_fay" wrote:

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


Jarek Kujawa[_2_]

Next without For..?
 
insert "End If" instead of "Else"

On 29 Kwi, 12:28, merry_fay
wrote:
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



RonaldoOneNil

Next without For..?
 
Change Else to End if

"merry_fay" wrote:

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


merry_fay

Next without For..?
 
Thankyou -I must have beeen having a really blond 5 mins!!

"Jacob Skaria" wrote:

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

--
If this post helps click Yes
---------------
Jacob Skaria


"merry_fay" wrote:

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


Dana DeLouis

Next without For..?
 
merry_fay wrote:
Thankyou -I must have beeen having a really blond 5 mins!!

"Jacob Skaria" wrote:

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

--
If this post helps click Yes
---------------
Jacob Skaria


"merry_fay" wrote:

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



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


All times are GMT +1. The time now is 12:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com