JordanCooper
New Member
- Joined
- Aug 22, 2018
- Messages
- 2
So I have this code:
and it works well but it logs on sheet 2 everytime the value is wrote in B14:J14. In other words, on sheet 1, all 9 values are copied into sheet 2 along with the date and time, anytime one of the 9 values changes. My other code updates these values continuously and everytime it updates them it logs it on sheet 2. sheet 2 fills up in like 15 minutes (all 65000 lines).
Is there any way to execute this code once or twice a min? or change it so it only logs it when the value genuinely changes (not just updates the cell).
thanks,
Jordan
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim VRange As Range
Dim LastRow As Integer
Set VRange = Range("B14:J14")
Dim NewData As Range
Dim DataPage As Range
On Error Resume Next
Application.ScreenUpdating = False
LastRow = Sheets("Sheet2").Range("A65536").End(xlUp).Row
Set NewData = Sheets("Sheet2").Range("A" & LastRow + 1)
Set DataPage = Sheets("Sheet1").Range("B14")
If Union(Target, VRange).Address = VRange.Address Then
NewData.Value = Now()
NewData.Offset(0, 1).Value = DataPage.Value
NewData.Offset(0, 2).Value = DataPage.Offset(0, 1).Value
NewData.Offset(0, 3).Value = DataPage.Offset(0, 2).Value
NewData.Offset(0, 4).Value = DataPage.Offset(0, 3).Value
NewData.Offset(0, 5).Value = DataPage.Offset(0, 4).Value
NewData.Offset(0, 6).Value = DataPage.Offset(0, 5).Value
NewData.Offset(0, 7).Value = DataPage.Offset(0, 6).Value
NewData.Offset(0, 8).Value = DataPage.Offset(0, 7).Value
NewData.Offset(0, 9).Value = DataPage.Offset(0, 8).Value
End If
Application.ScreenUpdating = True
End Sub
and it works well but it logs on sheet 2 everytime the value is wrote in B14:J14. In other words, on sheet 1, all 9 values are copied into sheet 2 along with the date and time, anytime one of the 9 values changes. My other code updates these values continuously and everytime it updates them it logs it on sheet 2. sheet 2 fills up in like 15 minutes (all 65000 lines).
Is there any way to execute this code once or twice a min? or change it so it only logs it when the value genuinely changes (not just updates the cell).
thanks,
Jordan
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim VRange As Range
Dim LastRow As Integer
Set VRange = Range("B14:J14")
Dim NewData As Range
Dim DataPage As Range
On Error Resume Next
Application.ScreenUpdating = False
LastRow = Sheets("Sheet2").Range("A65536").End(xlUp).Row
Set NewData = Sheets("Sheet2").Range("A" & LastRow + 1)
Set DataPage = Sheets("Sheet1").Range("B14")
If Union(Target, VRange).Address = VRange.Address Then
NewData.Value = Now()
NewData.Offset(0, 1).Value = DataPage.Value
NewData.Offset(0, 2).Value = DataPage.Offset(0, 1).Value
NewData.Offset(0, 3).Value = DataPage.Offset(0, 2).Value
NewData.Offset(0, 4).Value = DataPage.Offset(0, 3).Value
NewData.Offset(0, 5).Value = DataPage.Offset(0, 4).Value
NewData.Offset(0, 6).Value = DataPage.Offset(0, 5).Value
NewData.Offset(0, 7).Value = DataPage.Offset(0, 6).Value
NewData.Offset(0, 8).Value = DataPage.Offset(0, 7).Value
NewData.Offset(0, 9).Value = DataPage.Offset(0, 8).Value
End If
Application.ScreenUpdating = True
End Sub