Vba multiple if target column error 13

AlexGill89

New Member
Joined
Jul 25, 2018
Messages
6
Hi all,
I'm trying to set up a referral tracking sheet that monitors when data is entered in a cell and records the date. It was working but as I've added code it has started throwing up errors and I'm not sure if it can be fixed. Please see code below.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

With Target

If Target.Cells.Count <> 1 Then Exit Sub

If Target.Column = 12 And .Value = "Started" And Target.Offset(0, 1).Value = "" Then

        Target.Offset(0, 1) = Format(Now(), "DD/MM/YY")

    End If

    If Target.Column = 12 And .Value = "Completed" And Target.Offset(0, 2).Value = "" Then

        Target.Offset(0, 2) = Format(Now(), "DD/MM/YY")

    End If

    If Target.Column = 5 And Target.Offset(0, -1).Value = "" Then

        Target.Offset(0, -1) = Format(Now(), "DD/MM/YY")

    End If

     If Target.Column = 16 And .Value = "Job Offer" And Target.Offset(0, 1).Value = "" Then

        Target.Offset(0, 1) = Format(Now(), "DD/MM/YY")

    End If

If Target.Column <> 9 And Target.Column <> 11 And Target.Column <> 5 Then Exit Sub

If Target.Row = 1 Then Exit Sub

If Target.Row = 2 Then Exit Sub

If Target.Row = 3 Then Exit Sub

If IsEmpty(Target) Then Exit Sub

Dim strNewText$, strCommentOld$, strCommentNew$

strNewText = .Text

If Not .Comment Is Nothing Then

strCommentOld = .Comment.Text & Chr(10) & Chr(10)

Else

strCommentOld = ""

End If

On Error Resume Next

.Comment.Delete

Err.Clear

.AddComment

.Comment.Visible = False

.Comment.Text Text:=strCommentOld & _

Format(VBA.Now, "DD/MM/YYYY at h:MM AM/PM") & Chr(10) & strNewText

.Comment.Shape.TextFrame.AutoSize = True

End With

End Sub
Column 12 tracks starts and completions (cells have list data validation on them) column 5 is initial referrals and 16 tracks the job offers. I need to know the date of when these change.

I have the comment code as the columns with the dates are hidden. This seems to work okay.

Sorry this is vague it's not something I do regularly enough.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Could you add either a sample workbook or at least a screenshot showing examples of how your other columns are laid out to help with this.

Also details of what error(s) you are getting and on what lines of code.
 
Upvote 0
I had some cells with =date value set up to convert the text to actual date format. That seems to have caused the issue.

I will just have to run "text to columns" when I need to extract stats. Is there any other way of doing it? The codes purpose is to record the date whenever details are entered in those columns but it appears as text rather than "date" if that makes sense?

I will upload an image later.
 
Upvote 0
If you just want the date use
VBA Code:
Target.Offset(0, 1) = Date
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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