Solved

Help with a loop statement in VBA

Posted on 2014-02-27
2
199 Views
Last Modified: 2014-03-13
Hi all.  I have some code that screenscrapes some data.  What happens is a screen brings up some data, say all of my employees, then it checks to see if there is another sheet of employees.  If the bottom of the screen says 'done' i want the code to stop.  Unfortunetly, even thought the screen says 'done' it finishes the code before ending the loop.  

To be honest I don't even know if a loop statement is correct.  But below is an example of the code.  As you can see, it goes through the whole loop.  I need to know how to break the loop at the end of each section.  The comment 'Check for More Employees.. is where the condition should look for "Done" and stop processing.  Make sense?

 Do Until ....area(1, 2) = "Done"
             
'Emp Info 1
            E1 = Trim(Emp)
'Emp Info 2
            E2 = Trim(Emp)
'Emp Info 3
            E3 = Trim(Emp)
'Emp Info 4
            E4 = Trim(Emp)
'Emp Info 5
            E5 = Trim(Emp)

'Check for More Employees            
...SendKeys ("<NEXT>")

'Emp Info 6
            E6 = Trim(Emp)
'Emp Info 7
            E7 = Trim(Emp)
'Emp Info 8
            E8 = Trim(Emp)
'Emp Info 9
            E9 = Trim(Emp)
'Emp Info 10
            E10 = Trim(Emp)

'Check for More Employees            
...SendKeys ("<NEXT>")
       
'Emp Info 11
            E11 = Trim(Emp)
'Emp Info 12
            E12 = Trim(Emp)
'Emp Info 13
            E13 = Trim(Emp)
'Emp Info 14
            E14 = Trim(Emp)
'Emp Info 15
            E15 = Trim(Emp)

'Check for More Employees            
...SendKeys ("<NEXT>")
       
'Emp Info 16
            E16 = Trim(Emp)
'Emp Info 17
            E17 = Trim(Emp)
'Emp Info 18
            E18 = Trim(Emp)
'Emp Info 19
            E19 = Trim(Emp)
'Emp Info 20
            E20 = Trim(Emp)
       
        Loop
0
Comment
Question by:farmingtonis
[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 Comments
 

Author Comment

by:farmingtonis
ID: 39892297
Oh forgot to say thanks in advance :)
0
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 39892324
In the section where you want the loop to stop running put in an if statement.  If it comes back true then exit do


If [condition] Then Exit Do

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 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