PC Review


Reply
Thread Tools Rate Thread

Copy and paste range ontime

 
 
Rob
Guest
Posts: n/a
 
      25th Feb 2010
Hi,
I need to copy a static range and paste to specific cells at specific times.
The time interval is over 370 minutes. Here is the code that seems to work
well.

Sub CopyVolume1()
Range("C2:C4").Select
Selection.Copy
Range("D2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

Public Sub Time()
Application.OnTime TimeValue("14:07:00"), "CopyVolume1"
Application.OnTime TimeValue("14:08:00"), "CopyVolume2"
Application.OnTime TimeValue("14:09:00"), "CopyVolume3"
End Sub

Sub CopyVolume2()
Range("C2:C4").Select
Selection.Copy
Range("e2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

Sub CopyVolume3()
Range("C2:C4").Select
Selection.Copy
Range("f2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

Is there a way to do this with out having to copy and paste the Sub
CopyVolume3
until I have 370 Sub CopyVolumes and 370 Application.OnTime
TimeValue("14:09:00"), "CopyVolume3". Each time having to enter the various
parameters ?


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      25th Feb 2010
I've never set up 370 different ontime routines and I'm not sure how excel will
react.

Instead, I'd use a single ontime procedure that instructs itself to run once
more in a minute.

This is based on Chip Pearson's OnTime instructions:
http://www.cpearson.com/Excel/OnTime.aspx

(Untested, but it did compile)

Option Explicit
Public RunWhen As Double
Public Const cRunWhat = "DoTheCopy" ' the name of the procedure to run
Dim DestCell As Range
Dim sCtr As Long
Dim WhichSheet As Range
Sub StartTimer()

If WhichSheet Is Nothing Then
'initialize the variables
Set WhichSheet = ThisWorkbook.Worksheets("sheet1")
Set DestCell = WhichSheet.Range("c2")
sCtr = 1
RunWhen = Now + TimeSerial(14, 7, 0)
End If

Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True
End Sub
Sub TheSub()

With WhichSheet
.Range("C2:C4").Copy
DestCell.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=False
End With

'get ready for next time
If sCtr <= 370 Then
sCtr = sCtr + 1
RunWhen = RunWhen + TimeSerial(0, 1, 0)
Set DestCell = DestCell.Offset(0, 1)
StartTimer ' Reschedule the procedure
End If
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=False
End Sub



Rob wrote:
>
> Hi,
> I need to copy a static range and paste to specific cells at specific times.
> The time interval is over 370 minutes. Here is the code that seems to work
> well.
>
> Sub CopyVolume1()
> Range("C2:C4").Select
> Selection.Copy
> Range("D2").Select
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=False
> End Sub
>
> Public Sub Time()
> Application.OnTime TimeValue("14:07:00"), "CopyVolume1"
> Application.OnTime TimeValue("14:08:00"), "CopyVolume2"
> Application.OnTime TimeValue("14:09:00"), "CopyVolume3"
> End Sub
>
> Sub CopyVolume2()
> Range("C2:C4").Select
> Selection.Copy
> Range("e2").Select
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=False
> End Sub
>
> Sub CopyVolume3()
> Range("C2:C4").Select
> Selection.Copy
> Range("f2").Select
> Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> :=False, Transpose:=False
> End Sub
>
> Is there a way to do this with out having to copy and paste the Sub
> CopyVolume3
> until I have 370 Sub CopyVolumes and 370 Application.OnTime
> TimeValue("14:09:00"), "CopyVolume3". Each time having to enter the various
> parameters ?


--

Dave Peterson
 
Reply With Quote
 
Rob
Guest
Posts: n/a
 
      26th Feb 2010


"Dave Peterson" wrote:

> I've never set up 370 different ontime routines and I'm not sure how excel will
> react.
>
> Instead, I'd use a single ontime procedure that instructs itself to run once
> more in a minute.
>
> This is based on Chip Pearson's OnTime instructions:
> http://www.cpearson.com/Excel/OnTime.aspx
>
> (Untested, but it did compile)
>
> Option Explicit
> Public RunWhen As Double
> Public Const cRunWhat = "DoTheCopy" ' the name of the procedure to run
> Dim DestCell As Range
> Dim sCtr As Long
> Dim WhichSheet As Range
> Sub StartTimer()
>
> If WhichSheet Is Nothing Then
> 'initialize the variables
> Set WhichSheet = ThisWorkbook.Worksheets("sheet1")
> Set DestCell = WhichSheet.Range("c2")
> sCtr = 1
> RunWhen = Now + TimeSerial(14, 7, 0)
> End If
>
> Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
> Schedule:=True
> End Sub
> Sub TheSub()
>
> With WhichSheet
> .Range("C2:C4").Copy
> DestCell.PasteSpecial Paste:=xlPasteValues, _
> Operation:=xlNone, _
> SkipBlanks:=False, _
> Transpose:=False
> End With
>
> 'get ready for next time
> If sCtr <= 370 Then
> sCtr = sCtr + 1
> RunWhen = RunWhen + TimeSerial(0, 1, 0)
> Set DestCell = DestCell.Offset(0, 1)
> StartTimer ' Reschedule the procedure
> End If
> End Sub
> Sub StopTimer()
> On Error Resume Next
> Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
> Schedule:=False
> End Sub
>
>
>
> Rob wrote:
> >
> > Hi,
> > I need to copy a static range and paste to specific cells at specific times.
> > The time interval is over 370 minutes. Here is the code that seems to work
> > well.
> >
> > Sub CopyVolume1()
> > Range("C2:C4").Select
> > Selection.Copy
> > Range("D2").Select
> > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> > SkipBlanks _
> > :=False, Transpose:=False
> > End Sub
> >
> > Public Sub Time()
> > Application.OnTime TimeValue("14:07:00"), "CopyVolume1"
> > Application.OnTime TimeValue("14:08:00"), "CopyVolume2"
> > Application.OnTime TimeValue("14:09:00"), "CopyVolume3"
> > End Sub
> >
> > Sub CopyVolume2()
> > Range("C2:C4").Select
> > Selection.Copy
> > Range("e2").Select
> > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> > SkipBlanks _
> > :=False, Transpose:=False
> > End Sub
> >
> > Sub CopyVolume3()
> > Range("C2:C4").Select
> > Selection.Copy
> > Range("f2").Select
> > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> > SkipBlanks _
> > :=False, Transpose:=False
> > End Sub
> >
> > Is there a way to do this with out having to copy and paste the Sub
> > CopyVolume3
> > until I have 370 Sub CopyVolumes and 370 Application.OnTime
> > TimeValue("14:09:00"), "CopyVolume3". Each time having to enter the various
> > parameters ?

>
> --
>
> Dave Peterson
> .
> Thank you Dave.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy & paste range nc Microsoft Excel Programming 4 20th Jul 2009 05:08 AM
Find %ontime & SUMIF ontime ie: find matching sets within Range... Chris T-M Microsoft Excel Worksheet Functions 3 10th Oct 2008 08:14 PM
copy range and paste into every 3rd cell of new range thomsonpa Microsoft Excel New Users 4 3rd Dec 2007 01:47 PM
Copy/Paste Range mastermind Microsoft Excel Programming 2 22nd Dec 2006 07:04 PM
Copy paste range Marc Bell Microsoft Excel Programming 2 16th Feb 2004 01:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 AM.