Solved

Exit while in vba - not working

Posted on 2011-09-30
4
461 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to Auto-fill data in Database 2 19
AutoFilter Delete not keeping Headers? 2 13
Excel 3 24
Quickbooks - Merging data 3 8
What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
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.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now