Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Slowing down a "For Next"  Loop in Visual basic

Posted on 2013-11-20
4
Medium Priority
?
359 Views
Last Modified: 2014-01-06
I have the following code in Excel.
It basically, moves back and forth from Excel to my DOS based system
and Copy's and Pastes some information.
I'd just like to slow it down, so I can see what lines are not being copied.

I'd just like a 2 second delay on each loop.
I know how to do that in other programming languages I've used.
How can I do that in Visual Basic?




Sub sendtocp()
AppActivate "My Program"
For i = 3 To 21



 SendKeys Sheet1.Cells(i, 3), True
 SendKeys "~", True
 SendKeys Sheet1.Cells(i, 5), True
 SendKeys "~", True
 SendKeys Sheet1.Cells(i, 5), True
 SendKeys "~", True
 SendKeys "~", True
 y = 1
 For j = 1 To 10000
 y = y + 1
 Next j
Next i
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub
0
Comment
Question by:James Powell
[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
4 Comments
 
LVL 9

Accepted Solution

by:
WebDevEM earned 900 total points
ID: 39662814
Hi,

I think what you're looking for would be
Sleep 2000 'Number of milliseconds to pause

Open in new window

There's a site called MrExcel.com that has some VERY handy tips, and I found this on it.  I hope it helps!

WebDevEM
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39663503
Do note, as in the link provided by WebDevEM, you have to declare the Sleep() API before you can use it:

    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
0
 
LVL 40
ID: 39664658
The .NET topic has nothing to do with VBA in Excel because Visual Basic .NET and VBA are quite different.

The Microsoft Access topic does not help much either, because although both Excel and Access use VBA, they do it in different ways.

You are losing potential experts by defining useless topics in your questions. Aren't there VBA and Excel topics?
0
 
LVL 13

Expert Comment

by:Surone1
ID: 39674646
i reccomend not using sleep since it will "freeze" things up.
as an alternative you could try something like this :


starttime = Now 'i put this in for debugging only
endtime = DateAdd("s", 90, Now) 'determine endtime
Do While endtime > Now 'start 90 second loop
Label1.Caption = Now 'do sonmething OR NOT!
DoEvents 'prevent this from freezing
Loop
0

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

730 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