Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default What is causing "Block if without End if" error?

Here's my code thus far:

For Each rCell In rOrigCtyList
strOrig = rCell.Value
strOutcomes = rCell.Offset(0, 3).Value
lCurRow = rCell.Row
If strOrig < "DYC" Then
If strOutcomes < "DYC" Then
If strOutcomes < strOrig Then
lOrigCtyNo = Left(strOrig, 2)
lOutcomesNo = Left(strOutcomes, 2)

If lOrigCtyNo lOutcomesNo Then
Range(rCell, rCell.Offset(0, 2)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(-1, 0) = strOutcomes
End If

If lOrigCtyNo < lOutcomesNo Then
Range(rCell.Offset(0, 3), rCell.Offset(0,
13)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(0, 3) = strOrig
End If

End If
Else
Range(rCell.Offset(0, 3), rCell.Offset(0, 13)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(0, 3) = strOrig

End If
Else: End Sub <-----ERROR
End If
Next rCell
End Sub

I'm getting a block if without end if error at the marked line. I've
matched and rematched the If's and End Ifs. They match. So what am I
missing to cause the error? I want to exit the program when strOrig <
"DYC' is false.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default What is causing "Block if without End if" error?

End Sub is the unique end tag. What you want is Exit Sub.

HTH. Best wishes Harald

"davegb" skrev i melding
oups.com...
Here's my code thus far:

For Each rCell In rOrigCtyList
strOrig = rCell.Value
strOutcomes = rCell.Offset(0, 3).Value
lCurRow = rCell.Row
If strOrig < "DYC" Then
If strOutcomes < "DYC" Then
If strOutcomes < strOrig Then
lOrigCtyNo = Left(strOrig, 2)
lOutcomesNo = Left(strOutcomes, 2)

If lOrigCtyNo lOutcomesNo Then
Range(rCell, rCell.Offset(0, 2)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(-1, 0) = strOutcomes
End If

If lOrigCtyNo < lOutcomesNo Then
Range(rCell.Offset(0, 3), rCell.Offset(0,
13)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(0, 3) = strOrig
End If

End If
Else
Range(rCell.Offset(0, 3), rCell.Offset(0, 13)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(0, 3) = strOrig

End If
Else: End Sub <-----ERROR
End If
Next rCell
End Sub

I'm getting a block if without end if error at the marked line. I've
matched and rematched the If's and End Ifs. They match. So what am I
missing to cause the error? I want to exit the program when strOrig <
"DYC' is false.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default What is causing "Block if without End if" error?


Harald Staff wrote:
End Sub is the unique end tag. What you want is Exit Sub.

HTH. Best wishes Harald

"davegb" skrev i melding
oups.com...
Here's my code thus far:

For Each rCell In rOrigCtyList
strOrig = rCell.Value
strOutcomes = rCell.Offset(0, 3).Value
lCurRow = rCell.Row
If strOrig < "DYC" Then
If strOutcomes < "DYC" Then
If strOutcomes < strOrig Then
lOrigCtyNo = Left(strOrig, 2)
lOutcomesNo = Left(strOutcomes, 2)


Thanks to both of you!
If lOrigCtyNo lOutcomesNo Then
Range(rCell, rCell.Offset(0, 2)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(-1, 0) = strOutcomes
End If

If lOrigCtyNo < lOutcomesNo Then
Range(rCell.Offset(0, 3), rCell.Offset(0,
13)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(0, 3) = strOrig
End If

End If
Else
Range(rCell.Offset(0, 3), rCell.Offset(0, 13)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(0, 3) = strOrig

End If
Else: End Sub <-----ERROR
End If
Next rCell
End Sub

I'm getting a block if without end if error at the marked line. I've
matched and rematched the If's and End Ifs. They match. So what am I
missing to cause the error? I want to exit the program when strOrig <
"DYC' is false.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default What is causing "Block if without End if" error?

Dave,

A sub can have only one End Sub, which marks the end of the
procedure. No code can appear after an End Sub (except, of
course, other procedures). Rather than End Sub on the erroneous
line, I think you wanted an Exit Sub.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"davegb" wrote in message
oups.com...
Here's my code thus far:

For Each rCell In rOrigCtyList
strOrig = rCell.Value
strOutcomes = rCell.Offset(0, 3).Value
lCurRow = rCell.Row
If strOrig < "DYC" Then
If strOutcomes < "DYC" Then
If strOutcomes < strOrig Then
lOrigCtyNo = Left(strOrig, 2)
lOutcomesNo = Left(strOutcomes, 2)

If lOrigCtyNo lOutcomesNo Then
Range(rCell, rCell.Offset(0, 2)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(-1, 0) = strOutcomes
End If

If lOrigCtyNo < lOutcomesNo Then
Range(rCell.Offset(0, 3), rCell.Offset(0,
13)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(0, 3) = strOrig
End If

End If
Else
Range(rCell.Offset(0, 3), rCell.Offset(0,
13)).Select
Selection.Insert Shift:=xlDown
rCell.Offset(0, 3) = strOrig

End If
Else: End Sub <-----ERROR
End If
Next rCell
End Sub

I'm getting a block if without end if error at the marked line.
I've
matched and rematched the If's and End Ifs. They match. So what
am I
missing to cause the error? I want to exit the program when
strOrig <
"DYC' is false.



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
Find and Replace causing a "Text" cell to become a custom date--wh Benjamino5 Excel Discussion (Misc queries) 3 May 9th 07 09:26 PM
"Object Variable or With Block Variable Not Set" error help request Ken Loomis Excel Programming 8 June 27th 05 10:13 PM
Adding "And" clause in SQL string causing SQL Syntax error Android[_2_] Excel Programming 3 July 8th 04 09:36 PM
Need help in excel with "Statement invalid outside Type block. " error Brent[_6_] Excel Programming 3 January 17th 04 03:03 AM
"Run-time error 91: Object variable or With block not set" Snedker Excel Programming 0 January 10th 04 09:37 AM


All times are GMT +1. The time now is 05:43 PM.

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

About Us

"It's about Microsoft Excel"