Solved

Help with a loop statement in VBA

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

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

18 Experts available now in Live!

Get 1:1 Help Now