Solved

Help with a loop statement in VBA

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…

807 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