+ Reply to Thread
Results 1 to 3 of 3

Copy and Paste down at time interval

Hybrid View

  1. #1
    Registered User
    Join Date
    09-29-2016
    Location
    london
    MS-Off Ver
    2016
    Posts
    19

    Copy and Paste down at time interval

    Hi

    I am a very basic excel user and need help with some VBA please :-)

    I would like the value in cell F3 (which changes) to be copied and pasted down to F4 at a 30 sec interval, at the next 30 sec interval the value in F4 would move to F5 and a new "latest value" posted from F3 TO F4 and so on.

    Ideally would like a start and end time, so only does the function between these hours and is it not in these houses it pauses.

    Thanks in advance for any help.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Copy and Paste down at time interval

    See attached file, I hope that does what you need.
    Code used in the sheet:
    Private Sub Worksheet_Change(ByVal Target As Range)
       If Target.Cells.Count = 1 And Target.Address(0, 0) = "F3" Then
          If Not timerOn Then
             Call Module1.StartClock
          End If
       End If
    End Sub
    Code use in module 'Module1':
    Global myTime
    Global timerOn As Boolean
    Sub StartClock()
       With ThisWorkbook.Sheets("Sheet1")
          'Clear total elapsed time
          If .Range("b4") = "" Then
             .Range("b4") = 30
          ElseIf .Range("b4") = 1 Then
             lrow = .Cells(Rows.Count, "f").End(xlUp).Row
             If lrow > 3 Then
                .Range("f4:f" & lrow).Copy .Range("f5")
             End If
             .Range("f4") = .Range("f3")
             .Range("b4") = 30
             .Range("f3") = ""
             .Range("f3").Select
          Else
             .Range("b4") = .Range("b4") - 1
          End If
       
          If Time >= .Range("b1") And Time <= .Range("b2") Then
             timerOn = True
             nextTick = Now + TimeValue("00:00:01")
             myTime = nextTick
             
             Application.OnTime nextTick, "StartClock"
          Else
             Call StopClock
             .Range("b4").ClearContents
          End If
       End With
    End Sub
    Sub StopClock()
       'Stop OnTime event.
       'Returns error if already stopped and hense the on error handling.
       On Error Resume Next
       
       timerOn = False
       Application.OnTime _
          EarliestTime:=myTime, _
          Procedure:="StartClock", _
          Schedule:=False
       
       If Err.Number > 0 Then Exit Sub
       
       On Error GoTo 0
       With ThisWorkbook.Sheets("Sheet1")
          .Range("j3").Value = .Range("j1").Value - .Range("j2").Value
       End With
    End Sub
    Private Sub Worksheet_Change(ByVal Target As Range)
       If Target.Cells.Count = 1 And Target.Address(0, 0) = "F3" Then
          With ThisWorkbook.Sheets("Sheet1")
             If Time >= .Range("b1") And Time <= .Range("b2") Then
                .Range("b4") = 30
                Call StartClock
             End If
          End With
       End If
    End Sub
    Regards,
    Antonio
    Attached Files Attached Files

  3. #3
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Copy and Paste down at time interval

    In attached file I disabled the code that clear contents of Range F3 that you desired.

    Regards,
    Antonio
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy and Paste done at time interval
    By mcp77 in forum Excel General
    Replies: 5
    Last Post: 10-20-2016, 10:56 AM
  2. [SOLVED] Copy multiple Columns & paste in interval of 2 Columns
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-29-2015, 09:01 AM
  3. Replies: 1
    Last Post: 04-29-2014, 04:42 AM
  4. Replies: 0
    Last Post: 04-23-2012, 10:06 AM
  5. Refresh cells after a particular time interval and copy into another file :)
    By Spasm in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-30-2011, 01:56 AM
  6. copy paste with interval
    By pani_hcu in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-18-2009, 01:27 PM
  7. copy and paste of columns with interval
    By pani_hcu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2009, 10:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1