Delay VBA before running

Russk68

Well-known Member
Joined
May 1, 2006
Messages
589
Office Version
  1. 365
Platform
  1. MacOS
Hi all
I am using this code (Courtesy of Fluff)

Private Sub Worksheet_Activate()
Range("A:A").AutoFilter 1, "<>0"
End Sub

The issue that I'm having is that when I open the sheet with this code, it runs before the sheet is calculated. The reason for that is that I have calculation set to manual and the sheet calculates when I leave another sheet.

I would just like to delay this code for about 1 sec.

Thank you!

Russ
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
perhaps
Code:
Application.Wait Now + TimeValue("00:00:01")
 
Upvote 0
Hi Yongle
Thanks for posting
This code works but it's not doing what I expected. I think it's delaying the calculation as well, which is a calculation macro from the other sheet. I have to change sheets twice for the calculation to take effect. I'm going to post a new question about re-activating a sheet.
Thank you!
 
Upvote 0
You may be able to use the Worksheet_Calculate event
I think it triggers after the sheet calculates
Try putting the auto-filter code there instead to see if the problem is resolved.
May need to add a condition later to only make it do this once after sheet selected
Let me know how you get on
 
Upvote 0
this introduces a delay

Code:
Private Sub Worksheet_Activate()
    Dim a As Long    
    For a = 1 To 500
        Me.Activate
    Next a[COLOR=#006400][/COLOR]  
    Range("A:A").AutoFilter 1, "<>0"
End Sub

amended to measure the delay
Code:
Private Sub Worksheet_Activate()
    Dim a As Long, b As Double: b = Timer    
    For a = 1 To 500
        Me.Activate
    Next a
    Debug.Print Timer - b      [I][COLOR=#006400] 'see delay time in seconds in immediate window[/COLOR][/I]
    Range("A:A").AutoFilter 1, "<>0"
End Sub
 
Upvote 0
Hi Yongle,
I was having the same issue with all the options. I just decided to let the sheet calculate with a change event.
Thank you for your help!
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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