The following code creates/updates a date and timestamp for each time I click the command button to save the order/row. "TIMESTAMP" is a named range (Column 106) in the worksheet named: "MASTER". The code is entered within the worksheet object "MASTER". I tried to change Dim r As Range to Dim r As String because Column 106 in the worksheet is formatted as Text, but that didn't help. I also tried to Debug.Print the error line, but I must not be doing that right because I get no results in the Immediate Window.
However, I'm getting a Run-time error '13' - Type mismatch.
Thank you in advance for your help.
'***TIMESTAMP***
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Range
Dim Intersection As Range
Dim cell As Range
Set r = Range("TIMESTAMP")
Set Intersection = Intersect(r, Target)
If Intersection Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each cell In Intersection
Range(r & cell.Row).Value = Date & " " & Time 'run-time error '13' - Type mismatch
Next cell
Application.EnableEvents = True
End Sub
I'm editing this post to show what I've tried with no success.
There are probably a handful of ways to go about it, but this seemed to work for me:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lr As Long
Dim a As Range
Application.EnableEvents = False
Sheets("MASTER").Cells(Target.Row, Range("TIMESTAMP").Column).Value = Date & " " & Time
lr = Sheets("MASTER").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set a = ThisWorkbook.Names("TIMESTAMP").RefersToRange.CurrentRegion
Set a = Range("TIMESTAMP").Resize(lr)
a.Name = "TIMESTAMP"
Application.EnableEvents = True
End Sub
This should update the named range "TIMESTAMP" to include whatever row has been changed.
You should update the sheet references to match your workbook. Let me know if you have any problems or if it's not working as expected.
Good luck!