Solved

Exit while in vba - not working

Posted on 2011-09-30
4
466 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
Arno Koster 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:Arno Koster
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

751 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