VBA Timestamp/Run-time error 13

bencharn

New Member
Joined
Jul 27, 2018
Messages
3
Hello all,

First time posting, I'm having trouble with a simple VBA sub I've been working on. The idea is that the code drops a timestamp into a specific cell when the Plan-Do-Check-Accept (PDCA) status of that row changes.

Code:
Sub Worksheet_Change(ByVal Target As Range)
   Dim D As Range: Set D = Range("D:D")
   Dim v As String
    
   If Intersect(Target, D) Is Nothing Then
      Exit Sub
   End If
    
   Application.EnableEvents = False
      v = Target.Value
      If v = "P" Then Target.Offset(0, 1) = Now()
      If v = "D" Then Target.Offset(0, 2) = Now()
      If v = "C" Then Target.Offset(0, 3) = Now()
      If v = "A" Then Target.Offset(0, 4) = Now()
   Application.EnableEvents = True
   
End Sub

The code was running smoothly, however recent usage has been giving a Run-time error 13. I've worked the mismatch error is occuring between v (string) & Target.Value (variant), but I'm wondering what the easiest way is to fix this mismatch?

Thanks for your time!

Ben
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
When does it happen? When you clear cells? Or change more than one cell at once?
 
Upvote 0
Hi Steve, this happens as soon as I try and change the 'v' value. It also happens when I add additional rows to the table this code is working on.

When I debug the code, it highlights this line:
Code:
v = Target.Value
 
Upvote 0
Have a try with this:

Code:
Dim rng As Range, c As Range

Set rng = Intersect(Target, Range("D:D"))

If Not rng Is Nothing Then
    For Each c In rng
        With c
            Select Case .Value
                Case "P": .Offset(0, 1) = Now()
                Case "D": .Offset(0, 2) = Now()
                Case "C": .Offset(0, 3) = Now()
                Case "A": .Offset(0, 4) = Now()
            End Select
        End With
    Next
End If
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top