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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
What are you actually trying to do?

Is this for debugging purposes, or something else?
 
Upvote 0
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.
 
Upvote 0
Well how about using breakpoints?
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

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
Back
Top