![]() |
Finding the "Block If without End If" error
Hi -
It's been a while since I got this error, and eventually I found it. My steps to find it are below, but do y'all have any other tips/techniques? The sub was pretty large with a lot of IF ... Then Elseif Else logic. Thanks. 1. Code most recently changed 2. Comment out chunks of it, compile until error goes away 3. Find in last commented out section via searching for "end if", fix, remove commented out code, recompile. -- Neal Z |
Finding the "Block If without End If" error
Here are some tips
When ever you type an IF statement, before you ever type your statements inside the IF statement that need to be executed, immediatly type the END IF statement: IF condition THEN ' then go back and fill this in END IF do the same for WITH...END WITH, FOR loops, etc... If you have a huge procedure like that where it is difficult to find an error, you should consider breaking it down into smaller sub-procedures and calling all the sub-procedures from the main procedure. HTH, Conan Kelly "Neal Zimm" wrote in message ... Hi - It's been a while since I got this error, and eventually I found it. My steps to find it are below, but do y'all have any other tips/techniques? The sub was pretty large with a lot of IF ... Then Elseif Else logic. Thanks. 1. Code most recently changed 2. Comment out chunks of it, compile until error goes away 3. Find in last commented out section via searching for "end if", fix, remove commented out code, recompile. -- Neal Z |
Finding the "Block If without End If" error
In addition, you can make it ONE line so there is no "end if". If too long,
use the continuation character after a space ie: if xxxxxxxxxx _ -- Don Guillett SalesAid Software "Neal Zimm" wrote in message ... Hi - It's been a while since I got this error, and eventually I found it. My steps to find it are below, but do y'all have any other tips/techniques? The sub was pretty large with a lot of IF ... Then Elseif Else logic. Thanks. 1. Code most recently changed 2. Comment out chunks of it, compile until error goes away 3. Find in last commented out section via searching for "end if", fix, remove commented out code, recompile. -- Neal Z |
Finding the "Block If without End If" error
Hi,
It is common to indent the code, so it is easier to read. This is sort of like what you are doing with the commenting out, just makes things easier to see. If you have enough Nested Ifs , there might be the possibility of using Select Cse to simplify? -- David "Neal Zimm" wrote: Hi - It's been a while since I got this error, and eventually I found it. My steps to find it are below, but do y'all have any other tips/techniques? The sub was pretty large with a lot of IF ... Then Elseif Else logic. Thanks. 1. Code most recently changed 2. Comment out chunks of it, compile until error goes away 3. Find in last commented out section via searching for "end if", fix, remove commented out code, recompile. -- Neal Z |
Finding the "Block If without End If" error
Additional to David's suggestion to indent I highly recommend that when you
are writing code blocks writh both the beginning and ending at the same time. What I mean by that is that when you type in the if statement enter the else end if lines immediately. Then just fill in the code that you want in each section. This also applies to looping structures such as for next and do while... Just a helpful little habit to get into... -- HTH... Jim Thomlinson "Neal Zimm" wrote: Hi - It's been a while since I got this error, and eventually I found it. My steps to find it are below, but do y'all have any other tips/techniques? The sub was pretty large with a lot of IF ... Then Elseif Else logic. Thanks. 1. Code most recently changed 2. Comment out chunks of it, compile until error goes away 3. Find in last commented out section via searching for "end if", fix, remove commented out code, recompile. -- Neal Z |
Finding the "Block If without End If" error
Yup - thanks for the answer. I do indent, but the error was the result of a
bad cut and paste, (I think) -- Neal Z "David" wrote: Hi, It is common to indent the code, so it is easier to read. This is sort of like what you are doing with the commenting out, just makes things easier to see. If you have enough Nested Ifs , there might be the possibility of using Select Cse to simplify? -- David "Neal Zimm" wrote: Hi - It's been a while since I got this error, and eventually I found it. My steps to find it are below, but do y'all have any other tips/techniques? The sub was pretty large with a lot of IF ... Then Elseif Else logic. Thanks. 1. Code most recently changed 2. Comment out chunks of it, compile until error goes away 3. Find in last commented out section via searching for "end if", fix, remove commented out code, recompile. -- Neal Z |
Finding the "Block If without End If" error
Thanks much. I do most of what you mention, after I posted the question I
figured out, I think, the problem resulted from a bad cut and paste when moving a section of code. Thanks again. -- Neal Z "Conan Kelly" wrote: Here are some tips When ever you type an IF statement, before you ever type your statements inside the IF statement that need to be executed, immediatly type the END IF statement: IF condition THEN ' then go back and fill this in END IF do the same for WITH...END WITH, FOR loops, etc... If you have a huge procedure like that where it is difficult to find an error, you should consider breaking it down into smaller sub-procedures and calling all the sub-procedures from the main procedure. HTH, Conan Kelly "Neal Zimm" wrote in message ... Hi - It's been a while since I got this error, and eventually I found it. My steps to find it are below, but do y'all have any other tips/techniques? The sub was pretty large with a lot of IF ... Then Elseif Else logic. Thanks. 1. Code most recently changed 2. Comment out chunks of it, compile until error goes away 3. Find in last commented out section via searching for "end if", fix, remove commented out code, recompile. -- Neal Z |
Finding the "Block If without End If" error
Thanks much. I do most of what you mention, after I posted the question I
figured out, I think, the problem resulted from a bad cut and paste when moving a section of code. Thanks again. -- Neal Z "Jim Thomlinson" wrote: Additional to David's suggestion to indent I highly recommend that when you are writing code blocks writh both the beginning and ending at the same time. What I mean by that is that when you type in the if statement enter the else end if lines immediately. Then just fill in the code that you want in each section. This also applies to looping structures such as for next and do while... Just a helpful little habit to get into... -- HTH... Jim Thomlinson "Neal Zimm" wrote: Hi - It's been a while since I got this error, and eventually I found it. My steps to find it are below, but do y'all have any other tips/techniques? The sub was pretty large with a lot of IF ... Then Elseif Else logic. Thanks. 1. Code most recently changed 2. Comment out chunks of it, compile until error goes away 3. Find in last commented out section via searching for "end if", fix, remove commented out code, recompile. -- Neal Z |
Finding the "Block If without End If" error
Don -
Thanks much. Usually tho', since I really like to indent for readability, it would be rare that an If ..... then .....elseif .....then else ...... end if would fit on one line, but I'll keep the thought. -- Neal Z "Don Guillett" wrote: In addition, you can make it ONE line so there is no "end if". If too long, use the continuation character after a space ie: if xxxxxxxxxx _ -- Don Guillett SalesAid Software "Neal Zimm" wrote in message ... Hi - It's been a while since I got this error, and eventually I found it. My steps to find it are below, but do y'all have any other tips/techniques? The sub was pretty large with a lot of IF ... Then Elseif Else logic. Thanks. 1. Code most recently changed 2. Comment out chunks of it, compile until error goes away 3. Find in last commented out section via searching for "end if", fix, remove commented out code, recompile. -- Neal Z |
All times are GMT +1. The time now is 11:31 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com