"Run-time error '13': Type mismatch" when a VBA macro runs in Excel

aymar

New Member
Joined
Feb 12, 2015
Messages
3
Hello everyone,

I have really enjoyed finding answers to my issues, looking at past threads on this forum in the past. However, I am at a loss with this current issue.

I have a run time error 13 type mismatch when I run my VBA macro and it blocks on the following line:
Code:
Z = AddOlTask(Range(Target.Address).Offset(0, -6).Value & " " & Range(Target.Address).Value, "https://MYWEBSITE.com/admin/ticket.php?id=" & Range(Target.Address).Offset(0, -6), Now, Now)
            MsgBox "Action for ticket " & Range(Target.Address).Offset(0, -6).Value & " has been added to the todo list."

Basically, whenever there is a change in column Y, the macro is run but it blocks on that line.
Please find below the longer version of the code, it may be helpful.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim KeyCells As Range


    Set KeyCells = Range("Y:Y")


    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing Then


        If CStr(Range(Target.Address).Offset(0, 1).Value) = "Yes" Then
            Z = AddOlTask(Range(Target.Address).Offset(0, -6).Value & " " & Range(Target.Address).Value, "https://MYWEBSITE.com/admin/ticket.php?id=" & Range(Target.Address).Offset(0, -6), Now, Now)
            MsgBox "Action for ticket " & Range(Target.Address).Offset(0, -6).Value & " has been added to the todo list."
        End If


    End If
End Sub

Thanks a lot for your help, I have been looking for an answer for a while and I can't seem to solve this issue...
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Sorry, I forgot to specify that. It's a procedure that adds a task to Outlook.

Here is the code:
Code:
Function AddOlTask(sSubject As String, sBody As String, _
                    dtDueDate As Date, _
                    dtReminderDate As Date)
On Error GoTo Error_Handler
 
    Const olTaskItem = 3
    Dim OlApp As Object
    Dim OlTask As Object
 
    Set OlApp = CreateObject("Outlook.Application")
    Set OlTask = OlApp.CreateItem(olTaskItem)
 
    With OlTask
        .Subject = sSubject
        .DueDate = dtDueDate
        .Status = 1                 '0=not started, 1=in progress, 2=complete, 3=waiting,
                                    '4=deferred
        .Importance = 1             '0=low, 1=normal, 2=high
        .ReminderSet = False
        .ReminderTime = dtReminderDate
        .Categories = "Ticket" 'use any of the predefined Categorys or create your own
        .Body = sBody
        .Save   'use .Display if you wish the user to see the task form and make
                'them perform the save
    End With
 
Error_Handler_Exit:
    On Error Resume Next
    Set OlTask = Nothing
    Set OlApp = Nothing
    Exit Function
 
Error_Handler:
    MsgBox "The following error has occured" & vbCrLf & vbCrLf & "Error Number: " & _
    Err.Number & vbCrLf & "Error Source: AddOlkTask" & vbCrLf & "Error Description: " & _
    Err.Description, vbCritical, "An Error has Occured!"
    Resume Error_Handler_Exit
End Function

The source is VBA - Create an Outlook Task | DEVelopers HUT
 
Upvote 0
Try this:

Code:
Dim KeyCells As Range

Set KeyCells = Range("Y:Y")

If Target.Cells.Count > 1 Then Exit Sub

If Not Application.Intersect(KeyCells, Target) Is Nothing Then
    If UCase(Target.Offset(0, 1).Value) = "YES" Then
        Z = AddOlTask(Target.Offset(0, -6).Value & " " & Target.Value, "https://MYWEBSITE.com/admin/ticket.php?id=" & Target.Offset(0, -6).Value, Now, Now)
    End If
End If
 
Upvote 0
Thanks Steve, it works, it works well, and even though I couldn't have come up with it, I understand what's going on!
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,840
Members
449,471
Latest member
lachbee

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