Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with a loop statement in VBA

Posted on 2014-02-27
2
Medium Priority
?
201 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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