#1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default VBA Code

I have a seeming simple task that I can't figure out.

I have a macro set up to refresh a query and then do some copying and
pasting of cells.
What code can I use to tell the macro to wait until the query is finished
refreshing until it does the copy and paste?

Here is the simple code.

Sub GetData()
ThisWorkbook.RefreshAll

' I need the following code to be run after the refresh is finished'
Range("J5").Select
Selection.Copy
Range("J6:J65000").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.LargeScroll ToRight:=-1
Range("D1").Select

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default VBA Code

Preacher Man wrote:
I have a seeming simple task that I can't figure out.

I have a macro set up to refresh a query and then do some copying and
pasting of cells.
What code can I use to tell the macro to wait until the query is
finished refreshing until it does the copy and paste?

Here is the simple code.

Sub GetData()
ThisWorkbook.RefreshAll

' I need the following code to be run after the refresh is finished'
Range("J5").Select
Selection.Copy
Range("J6:J65000").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.LargeScroll ToRight:=-1
Range("D1").Select

End Sub




Hi,

maybe you can split your GetData macro in two macros:

Sub GetData()
ThisWorkbook.RefreshAll

Call CopyAndPaste

End Sub


Sub CopyAndPaste()
Range("J5").Copy Range("J6:J65000")
ActiveWindow.LargeScroll ToRight:=-1
Range("D1").Select

End Sub


--
Hope I helped you.

Thanks in advance for your feedback.

Ciao

Franz Verga from Italy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default VBA Code

Objects that have the BackgroundQuery property set to True are refreshed in
the background. You need to set them to false. That way the VBA will wait
until the refresh completes.


--
Gary''s Student


"Preacher Man" wrote:

I have a seeming simple task that I can't figure out.

I have a macro set up to refresh a query and then do some copying and
pasting of cells.
What code can I use to tell the macro to wait until the query is finished
refreshing until it does the copy and paste?

Here is the simple code.

Sub GetData()
ThisWorkbook.RefreshAll

' I need the following code to be run after the refresh is finished'
Range("J5").Select
Selection.Copy
Range("J6:J65000").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.LargeScroll ToRight:=-1
Range("D1").Select

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Code to conditional format all black after date specified in code? wx4usa Excel Discussion (Misc queries) 3 December 26th 08 07:06 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
Code stops when high lighting (Chips code) ste mac Excel Programming 6 May 2nd 06 01:39 PM
stubborn Excel crash when editing code with code, one solution Brian Murphy Excel Programming 0 February 20th 05 05:56 AM


All times are GMT +1. The time now is 12:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"