Solved

Exit while in vba - not working

Posted on 2011-09-30
4
463 Views
Last Modified: 2012-05-12
hi,

I am trying to use the exit while statement in VBa but it doesnt seem to pick the syntax, nither for end while

Very new to vba. would be great if any one could let me know whats the right syntax

If a = "" Then Exit While

END while

thanks
0
Comment
Question by:SameerMirza
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
akoster earned 500 total points
ID: 36891830
correct use of the while statement :

WHILE condition
[...]
WEND

if you want to exit the loop if a = "" then the correct way would be

WHILE condition AND A <> ""
[...]
WEND

if you want to use the exit construction, you'd better be using

DO
[....]
if a = "" then exit do
[...]
LOOP WHILE condition

0
 

Author Comment

by:SameerMirza
ID: 36891847
true.
I figuered it out. :)
0
 
LVL 19

Expert Comment

by:akoster
ID: 36891858
pay attention though that there is a difference in these code fragments :

x = 10
WHILE x < 5
   msgbox "this message will not be displayed"
   x = 25
WEND
DO
   msgbox "this message will be displayed"
LOOP WHILE x < 5

Open in new window

0
 

Author Closing Comment

by:SameerMirza
ID: 36998805
thanks
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question