View Single Post
 
Old 02-21-2019, 03:33 AM
Crillezzz Crillezzz is offline Windows 10 Office 2007
Novice
 
Join Date: Feb 2019
Posts: 2
Crillezzz is on a distinguished road
Default Copy one cell to another every hour

I have a macro that copies cell A1 to column I every hour.It copies A1 to I2 then A1 again to I3, I4, I5 and so on. But the list is too long. I'm only interested in the last few hours. I want the list to go from I2 to I30. So every time it should copy over a new number, it should delete the first one on I2 and move up the rest. The idea is that I will make a graph of the data.This is how the code looks. But the last code I do not know where it should be.Can anyone help me please?


Sentiment.xlsm

Option Explicit
Public dTime As Date

Sub ValueStore()
Dim dTime As Date
Range("I" & Cells(Rows.Count).Row).End(xlUp).Offset(1, 0).Value = Range("A1").Value
Call StartTimer

End Sub


Sub StartTimer()
dTime = Now + TimeValue("01:00:00")
Application.OnTime dTime, "ValueStore", Schedule:=True
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime dTime, "ValueStore", Schedule:=False
End Sub
__________________________________________________ _____________________________
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NR As Long
If Not Intersect(Target, Range("A1")) Is Nothing Then
NR = Range("I" & Cells(Rows.Count).Row).End(xlUp).Row + 1
Range("I" & NR).Value = Range("A1").Value
If NR > 30 Then Range("I2").Delete xlShiftUp
End If
End Sub
Reply With Quote