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.
- Open userform and search for an order/row
- Click save command button
- The runtime error pops up, so I click 'end', which closes the userform
- Open the userform again
- Search for the same order/row
- Click save command button
- No error message appears
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.
- Revision: Dim Intersection As String
- Compile error: Object required
- Error line: Set Intersection = Intersect(r, Target)
- Revision: Removed "Set" in Set Intersection = Intersect(r,Target)
- Compile error: Type mismatch
- Error line: If Intersect is Nothing Then Exit Sub
- Revision: Dim Intersection As Variant
- Run-time error '91': Object variable or With block variable not set
- Revision: Set Intersection = Intersect(r, Target)
- Brings me back to the original problem - Run-time error '13' Type mismatch on line: Range(r & cell.Row).Value = Date & " " & Time
There are probably a handful of ways to go about it, but this seemed to work for me:
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!