Is there a way to make the VBA codes run at a certain pace?

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
I know that I can ran the whole code (pressing F5) or manually run script by script (F8 for each line).

But is there a way to make it run like automatically but slower?

Thanks
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,357
Office Version
  1. 365
Platform
  1. Windows
What are you actually trying to do?

Is this for debugging purposes, or something else?
 

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
What are you actually trying to do?

Is this for debugging purposes, or something else?

Something else. I would like to illustrate to someone what the codes does but it is a long code so it is not very practical to press F8 for each line.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,357
Office Version
  1. 365
Platform
  1. Windows
Well how about using breakpoints?
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Or you could break it up with Message Boxes I 'spose...

Smitty
 

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
Hmmn yes I will try both suggestions, probably go with msgbox.

Thanks guys.
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

let me suggest a "Caveman technique" :LOL:

1.
copy your code to column A
insert a row between all rows (there are tricks to do them all at once)

2.
in column B
=IF(A1="","Sleep CLng(t)",A1)

3.
paste back to VBA
and insert 2 codelines
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Const t = 2000

example
Code:
Sub test1()
Range("A1") = Int(Rnd * 5555)
Range("A2") = Int(Rnd * 5555)
Range("A3") = Int(Rnd * 5555)
End Sub
  A                             B                             
1 Sub test1()                   Sub test1()                   
2                               Sleep CLng(t)                 
3 Range("A1") = Int(Rnd * 5555) Range("A1") = Int(Rnd * 5555) 
4                               Sleep CLng(t)                 
5 Range("A2") = Int(Rnd * 5555) Range("A2") = Int(Rnd * 5555) 
6                               Sleep CLng(t)                 
7 Range("A3") = Int(Rnd * 5555) Range("A3") = Int(Rnd * 5555) 
8                               Sleep CLng(t)                 
9 End Sub                       End Sub                       

test

[Table-It] version 07 by Erik Van Geit
Code:
RANGE FORMULA (1st cell)
B1:B9 =IF(A1="","Sleep CLng(t)",A1)

[Table-It] version 07 by Erik Van Geit

Code:
Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
   
Const t = 2000

Sub test1()
Sleep CLng(t)
Range("A1") = Int(Rnd * 5555)
Sleep CLng(t)
Range("A2") = Int(Rnd * 5555)
Sleep CLng(t)
Range("A3") = Int(Rnd * 5555)
Sleep CLng(t)
End Sub

kind regards,
Erik
 

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
Hi,

let me suggest a "Caveman technique" :LOL:

1.
copy your code to column A
insert a row between all rows (there are tricks to do them all at once)

2.
in column B
=IF(A1="","Sleep CLng(t)",A1)

3.
paste back to VBA
and insert 2 codelines
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Const t = 2000

example
Code:
Sub test1()
Range("A1") = Int(Rnd * 5555)
Range("A2") = Int(Rnd * 5555)
Range("A3") = Int(Rnd * 5555)
End Sub
  A                             B                             
1 Sub test1()                   Sub test1()                   
2                               Sleep CLng(t)                 
3 Range("A1") = Int(Rnd * 5555) Range("A1") = Int(Rnd * 5555) 
4                               Sleep CLng(t)                 
5 Range("A2") = Int(Rnd * 5555) Range("A2") = Int(Rnd * 5555) 
6                               Sleep CLng(t)                 
7 Range("A3") = Int(Rnd * 5555) Range("A3") = Int(Rnd * 5555) 
8                               Sleep CLng(t)                 
9 End Sub                       End Sub                       

test

[Table-It] version 07 by Erik Van Geit
Code:
RANGE FORMULA (1st cell)
B1:B9 =IF(A1="","Sleep CLng(t)",A1)

[Table-It] version 07 by Erik Van Geit

Code:
Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
   
Const t = 2000

Sub test1()
Sleep CLng(t)
Range("A1") = Int(Rnd * 5555)
Sleep CLng(t)
Range("A2") = Int(Rnd * 5555)
Sleep CLng(t)
Range("A3") = Int(Rnd * 5555)
Sleep CLng(t)
End Sub

kind regards,
Erik

Hi Erik,

Looks very interesting-will definitely try. BUt can you share with me the " trick" re

Code:
insert a row between all rows (there are tricks to do them all at once)

Thanks.
 

Forum statistics

Threads
1,181,647
Messages
5,931,208
Members
436,784
Latest member
amuljono

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top