Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Exit while in vba - not working

Posted on 2011-09-30
4
Medium Priority
?
473 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 2000 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

730 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