Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default 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

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
Excel Error :- "Too Many Cell Formats"...is there a way of finding FoS605 Excel Discussion (Misc queries) 4 June 30th 08 03:23 PM
To block "to "eliminate" of the picture of form, information Isaac[_2_] Excel Programming 0 June 29th 06 03:22 PM
What is causing "Block if without End if" error? davegb Excel Programming 3 September 8th 05 10:29 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 11:23 AM.

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"