Forever Forest

New Member
Joined
Feb 17, 2019
Messages
3
Hi all,

I have just used the following code, from this forum (Someone called Alan - Thanks Alan whoever you are!!), that does what I'm looking for.

My only problem is, the code works fine if the data I enter into A1 is manual. But if the value in A1 in coming from elsewhere in the sheet, I can't get the code below to work.

Does anyone have any ideas how I might try and solve this at all?

(many thanks in advance)

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lRow As Long
Dim vaData() As Variant
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub

ReDim vaData(1 To 1, 1 To 3)
vaData(1, 1) = Now()
vaData(1, 2) = Target.Address
vaData(1, 3) = Target.Resize(1, 1).Value
Application.EnableEvents = False
With Sheets("Sheet2")
lRow = .Cells(Rows.Count, "A").End(xlUp).Row + 1
.Range("A" & lRow & ":C" & lRow).Value = vaData
End With
Application.EnableEvents = True
End Sub
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
Does this work for you
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim keyCells As Range
   Set keyCells = Range("A1")
   On Error Resume Next
   Set keyCells = Application.Union(keyCells, keyCells.Precedents)
   On Error GoTo 0
   If Not Application.Intersect(keyCells, Target) Is Nothing Then
      With Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(, 3)
         .Value = Array(Now, "$A$1", Me.Range("A1").Value)
      End With
   End If
End Sub
 

Forever Forest

New Member
Joined
Feb 17, 2019
Messages
3
Hi & welcome to MrExcel.
Does this work for you
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim keyCells As Range
   Set keyCells = Range("A1")
   On Error Resume Next
   Set keyCells = Application.Union(keyCells, keyCells.Precedents)
   On Error GoTo 0
   If Not Application.Intersect(keyCells, Target) Is Nothing Then
      With Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(, 3)
         .Value = Array(Now, "$A$1", Me.Range("A1").Value)
      End With
   End If
End Sub


It does indeed! Thank you so much Fluff.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Forever Forest

New Member
Joined
Feb 17, 2019
Messages
3
Just one last question Fluff - if the data coming in to A1 is automated, and updating quite often, will this code still record that in Sheet 2? Or does it only work if I enter a value and manually press return/enter?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
That should work whenever a cell that A1 depends on is changed.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,445
Messages
5,528,801
Members
409,835
Latest member
Mafu1267

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top