Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DS DS is offline
external usenet poster
 
Posts: 117
Default Ifs, Selects & Loops Error Statements

Currently, if you have a macro which contains a number of "closed"
statements, such as IF, SELECT CASE, DO...LOOP etc, the VBA error-detection
system tends to be a little random in its identification of where the error
lies if one or more of the statements aren't closed. e.g. if you have three
"Select Case" statements within an "IF", and one of the "Select Case" isn't
closed with an "End Select" - VBA will frequently tell you that there is an
"Block If without End If", rather than a "Block Select without End Select"
which would make things easier to locate the bug in question. Especially as,
when you hit "debug" to the error, the highlighted area is the mistaken
location rather than the actual error area.

e.g.:

Sub Whatever()

hrng = 1

If 1 0 Then

Select Case hrng
Case 1
MsgBox "Yo!"
Case 2
MsgBox "uh-huh"
Case 3
MsgBox "Whoa!"

End If

End Sub

In this instance, the Select is not closed. When attempting to run, however,
the error message received is an "End If Without Block If" Compile Error, and
the "End If" is higlighted, rather than the "Select" which is not closed.

Obviously, the example above is very basic, but this would prove very useful
when there are hundreds upon hundreds of lines of code containing multiple
closed statements, and the current process reduces me to a wreck trawling
through line by line looking for an unclosed statement!

or I could just learn to always close, but that would be far too easy.... =:-)


----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/office/comm...el.programming
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
ADO & Loops: error in code? Santiago[_2_] Excel Programming 2 July 28th 05 07:25 PM
On Error and Loops ThisShouldBeEasy Excel Programming 1 June 8th 05 06:53 PM
loops and if statements lakey13[_2_] Excel Programming 1 November 5th 04 01:38 AM
loops and if statements lakey13 Excel Programming 1 November 3rd 04 03:50 AM
Error Handling and For-Next Loops SuperJas Excel Programming 2 May 28th 04 07:41 AM


All times are GMT +1. The time now is 09:27 PM.

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"