Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Next Without For Error

I am getting an error message of "Next without For" on the Next
RowCount Statement at the end of the following code. Can anyone tell
me why?

Frank

Sub Macro()

LastRw = 54
NewRowCount = 38
For RowCount = NewRowCount To LastRw Step 2
Ahead = Cells(RowCount, 5) - Cells(RowCount, 4)
If Ahead = 0 Then
Cells(RowCount, 6) = 0
ElseIf Ahead < 0 Then
Cells(RowCount, 6) = Ahead * -1
Ahead = 0
LastColumn = 18
NewColumnCount = 8
For ColumnCount = NewColumnCount To LastColumn Step 2
If Ahead = 0 Then
Cells(RowCount, ColumnCount) = Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2)

ElseIf Ahead 0 And Ahead Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) Then
Cells(RowCount, ColumnCount) = 0
Ahead = Ahead - (Cells(RowCount + 1, ColumnCount) - Cells(RowCount
+ 1, ColumnCount - 2))

ElseIf Ahead 0 And Ahead < Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) Then
Cells(RowCount, ColumnCount) = Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) - Ahead
Ahead = 0

End If
Next ColumnCount
Next RowCount

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Next Without For Error

This "IF" construct is missing a final ENDIF:

If Ahead = 0 Then
Cells(RowCount, 6) = 0
ElseIf Ahead < 0 Then

This kind of error would be easier to pickup if you used tabs more to
reflect the structure of your code. This also makes it easier to match
FOR/NEXT statements and other loops,etc.



Richard

--
Richard Marsden
Winwaed Software Technology LLC
http://www.winwaed.com
Tools and Add-ins for MapPoint - http://www.mapping-tools.com


wrote:
I am getting an error message of "Next without For" on the Next
RowCount Statement at the end of the following code. Can anyone tell
me why?

Frank

Sub Macro()

LastRw = 54
NewRowCount = 38
For RowCount = NewRowCount To LastRw Step 2
Ahead = Cells(RowCount, 5) - Cells(RowCount, 4)
If Ahead = 0 Then
Cells(RowCount, 6) = 0
ElseIf Ahead < 0 Then
Cells(RowCount, 6) = Ahead * -1
Ahead = 0
LastColumn = 18
NewColumnCount = 8
For ColumnCount = NewColumnCount To LastColumn Step 2
If Ahead = 0 Then
Cells(RowCount, ColumnCount) = Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2)

ElseIf Ahead 0 And Ahead Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) Then
Cells(RowCount, ColumnCount) = 0
Ahead = Ahead - (Cells(RowCount + 1, ColumnCount) - Cells(RowCount
+ 1, ColumnCount - 2))

ElseIf Ahead 0 And Ahead < Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) Then
Cells(RowCount, ColumnCount) = Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) - Ahead
Ahead = 0

End If
Next ColumnCount
Next RowCount

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Next Without For Error

On Jan 21, 8:34*pm, Richard Marsden
wrote:
This "IF" construct is missing a final ENDIF:

* * *If Ahead = 0 Then
* * *Cells(RowCount, 6) = 0
* * *ElseIf Ahead < 0 Then

This kind of error would be easier to pickup if you used tabs more to
reflect the structure of your code. This also makes it easier to match
FOR/NEXT statements and other loops,etc.

Richard

--
Richard Marsden
Winwaed Software Technology LLChttp://www.winwaed.com
Tools and Add-ins for MapPoint -http://www.mapping-tools.com



wrote:
I am getting an error message of "Next without For" on the Next
RowCount Statement at the end of the following code. *Can anyone tell
me why?


Frank


Sub Macro()


* * LastRw = 54
* * NewRowCount = 38
* * For RowCount = NewRowCount To LastRw Step 2
* * Ahead = Cells(RowCount, 5) - Cells(RowCount, 4)
* * If Ahead = 0 Then
* * Cells(RowCount, 6) = 0
* * ElseIf Ahead < 0 Then
* * Cells(RowCount, 6) = Ahead * -1
* * Ahead = 0
* * LastColumn = 18
* * NewColumnCount = 8
* * For ColumnCount = NewColumnCount To LastColumn Step 2
* * If Ahead = 0 Then
* * Cells(RowCount, ColumnCount) = Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2)


* * ElseIf Ahead 0 And Ahead Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) Then
* * Cells(RowCount, ColumnCount) = 0
* * Ahead = Ahead - (Cells(RowCount + 1, ColumnCount) - Cells(RowCount
+ 1, ColumnCount - 2))


* * ElseIf Ahead 0 And Ahead < Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) Then
* * Cells(RowCount, ColumnCount) = Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) - Ahead
* * Ahead = 0


* * End If
* * Next ColumnCount
* * Next RowCount


* * End Sub- Hide quoted text -


- Show quoted text -


Thanks for pointing out the simple error, and your advise to prevent
similar errors. I will use tabs more in the future.

Regards,
Frank
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Next Without For Error

you can also try smart indenter to help you out.

http://www.oaltd.co.uk/Indenter/Default.htm

--


Gary


wrote in message
...
On Jan 21, 8:34 pm, Richard Marsden
wrote:
This "IF" construct is missing a final ENDIF:

If Ahead = 0 Then
Cells(RowCount, 6) = 0
ElseIf Ahead < 0 Then

This kind of error would be easier to pickup if you used tabs more to
reflect the structure of your code. This also makes it easier to match
FOR/NEXT statements and other loops,etc.

Richard

--
Richard Marsden
Winwaed Software Technology LLChttp://www.winwaed.com
Tools and Add-ins for MapPoint -http://www.mapping-tools.com



wrote:
I am getting an error message of "Next without For" on the Next
RowCount Statement at the end of the following code. Can anyone tell
me why?


Frank


Sub Macro()


LastRw = 54
NewRowCount = 38
For RowCount = NewRowCount To LastRw Step 2
Ahead = Cells(RowCount, 5) - Cells(RowCount, 4)
If Ahead = 0 Then
Cells(RowCount, 6) = 0
ElseIf Ahead < 0 Then
Cells(RowCount, 6) = Ahead * -1
Ahead = 0
LastColumn = 18
NewColumnCount = 8
For ColumnCount = NewColumnCount To LastColumn Step 2
If Ahead = 0 Then
Cells(RowCount, ColumnCount) = Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2)


ElseIf Ahead 0 And Ahead Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) Then
Cells(RowCount, ColumnCount) = 0
Ahead = Ahead - (Cells(RowCount + 1, ColumnCount) - Cells(RowCount
+ 1, ColumnCount - 2))


ElseIf Ahead 0 And Ahead < Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) Then
Cells(RowCount, ColumnCount) = Cells(RowCount + 1, ColumnCount) -
Cells(RowCount + 1, ColumnCount - 2) - Ahead
Ahead = 0


End If
Next ColumnCount
Next RowCount


End Sub- Hide quoted text -


- Show quoted text -


Thanks for pointing out the simple error, and your advise to prevent
similar errors. I will use tabs more in the future.

Regards,
Frank


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Form Err.Raise error not trapped by entry procedure error handler [email protected] Excel Programming 1 February 8th 06 10:19 AM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM


All times are GMT +1. The time now is 06:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"