Copy column C to column D every X seconds

henryvii99

New Member
Joined
Apr 22, 2011
Messages
32
Dear everyone,

I have a macro which can copy the data from column D to column L and shift the existing data to the next column by the following script,

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LC As Long
If Not Intersect(Target, Range("D322")) Is Nothing Then
    Application.EnableEvents = False
    LC = Cells(4, Columns.Count).End(xlToLeft).Column + 1
    Range("D4:D322").Copy Destination:=Cells(4, LC)
    Application.EnableEvents = True
End If
End Sub

This time, I just to copy the value from C4:C204 to D4:204 every x seconds, without the need to shift the data.

But I want to control the update time by the input in column B, e.g. when B4 is 45, I want the cell to be copied from C4 to D4 every 45 seconds.

Many thanks in advance!:)
 
Got it to work:

Made line 4 Sub CopyC2D(), and had to remove ".xlsx" from 5th line for some reason.

Then when adding in WB and WS names works nice!
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
:oops: :oops: :oops:
Copy-paste error!! Here's the whole thing...
Code:
Sub CopyC2D()
Dim TimeOfDay As Double
Dim MyWB As String
Dim MyWS As String
    MyWB = "YourWorkBookNameHere.xlsx"
    MyWS = "YourWorkSheetNameHere"
    TimeOfDay = (Now() - Application.WorksheetFunction.RoundDown(Now(), 0))
    With Workbooks(MyWB).Worksheets(MyWS)
        If TimeOfDay > 10 / 24 And TimeOfDay < 22 / 24 Then
            .Range("C4:C204").Copy Destination:=.Range("D4:D204")
        End If
    End With
    Call CopyTime(MyWB, MyWS)
    
End Sub
Sub CopyTime(WB As String, WS As String)
Dim MyWorkbook As String
Dim MyWorksheet As String
    With Workbooks(WB).Worksheets(WS)
        If .Range("B4").Value > 0 Then
            Application.OnTime Now + TimeValue("00:00:" & .Range("B4").Value), "CopyC2D"
        End If
    End With
End Sub
 
Upvote 0
The post above has the wrong "stop time"...I had to set it later for testing and forgot to set it back.
In the line
Code:
 If TimeOfDay > 10 / 24 And TimeOfDay < 22 / 24 Then
Change "22 / 24" to "16 / 24" for 4PM.
(Note that this is based on the way Excel stores time, as the fraction of a day).
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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