Solved

Help with a loop statement in VBA

Posted on 2014-02-27
2
198 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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