View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default How to set up a delay to Private Sub Worksheet_Change(ByVal Target

If you use Application.Wait, you are liable to wait, while nothing else
happens, including updating of the data.

The Do While with DoEvents is a good approach. Another is to put the code
you want to run into another routine, and use Application.OnTime to invoke
it:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$J$245" Then
Application.OnTime Now + TimeValue("00:00:10"), "CodeToRunSoon"
End If
End Sub

In a regular module:

Sub CodeToRunSoon()
' your code
End Sub


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"ryguy7272" wrote in message
...
Something like this:
Application.Wait Now + TimeValue("00:00:10")

So, it may evolve into:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$J$245" Then

Application.Wait Now + TimeValue("00:00:10")

(my macro code)


End If
End Sub

--
RyGuy


"gordom" wrote:

Hi,
I have a sheet with a pivot table. The data from pivot table report are
modified and imported to another range of cells. The layout of this
cells is changed by macro. If I triggered the macro manually it works
fine. The problem starts if I want to execute the macro automatically
when one of the cells is changed (I use "Private Sub
Worksheet_Change(ByVal Target As Range)" event). Unfortunately macro
corrupts data in that case. I suppose that macro starts modifying the
layout before all data are fully imported from the pivot. I tried to set
up some delay to the event but couldn't figure out how to do so. Could
you please help me? Thanks in advance.
gordom



my code syntax

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$J$245" Then


(my macro code)


End If
End Sub