Run Time Error 13 - Type Mismatch - How to ignore Blank Dates??

StephenMatthews

New Member
Joined
Sep 26, 2013
Messages
28
Hi,

I keep getting a Run Time Error 13 – Type Mismatch on the below Highlighted Code below when a date field is blank, how can I add some additional code to ignore blank dates? The Macro is used so that when a Certificate date expires that 7 days prior to this a reminder e-mail is sent, some lines of data don’t have expiry dates hence they are blank and causing this error.

Thanks

Stephen.
Code:
Sub eMail()
Dim lRow As Integer
Dim i As Integer
Dim toDate As Date
Dim toList As String
Dim eSubject As String
Dim eBody As String
 
With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .DisplayAlerts = False
End With
 
Sheets(1).Select
lRow = Cells(Rows.Count, 5).End(xlUp).Row
 
For i = 2 To lRow
toDate = Replace(Cells(i, 16), ".", "/")
  If Left(Cells(i, 18), 5) <> "Mail" And toDate - Date <= 7 Then
     Set OutApp = CreateObject("Outlook.Application")
     Set OutMail = OutApp.CreateItem(0)
 
        toList = Cells(i, 5)
        eSubject = "Certificate Out of Date - " & Cells(i, 1) & " is due on " & Cells(i, 16)
        eBody = "Hi Maz" & vbCrLf & vbCrLf & "Certificate is due for renewal."
        
        On Error Resume Next
        With OutMail
        .To = toList
        .CC = ""
        .BCC = ""
        .Subject = eSubject
        .Body = eBody
        .bodyformat = 1
        '.Display
        .Send
        End With
 
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
 Cells(i, 17) = "Mail Sent " & Date + Time
End If
Next i
 
ActiveWorkbook.Save
 
With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .DisplayAlerts = True
End With
End Sub
 
Last edited by a moderator:
Sure. Move this line:

Code:
Set OutApp = CreateObject("Outlook.Application")

so that it is before this line:

Code:
For i = 2 To lRow

Hi Rory,

I've been asked by my colleague who I'm doing this for if we can expand this to include numerous searches in various other columns. Currently it pulls a date from column 16 which is now 20 on the example below:

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD="align: center"]10[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]16[/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]20[/TD]
[/TR]
[TR]
[TD="align: center"]H&S 1[/TD]
[TD="align: center"]H&S 2[/TD]
[TD="align: center"]H&S 3[/TD]
[TD="align: center"]H&S 4[/TD]
[TD="align: center"]H&S 5[/TD]
[TD="align: center"]H&S 6 [/TD]
[TD="align: center"]H&S 7[/TD]
[TD="align: center"]H&S 8[/TD]
[TD="align: center"]H&S 9 [/TD]
[TD]Insurance - Public[/TD]
[TD]Insurance - Employer[/TD]
[/TR]
[TR]
[TD="align: center"]01/01/17[/TD]
[TD="align: center"]01/02/17[/TD]
[TD="align: center"]01/03/17[/TD]
[TD="align: center"]01/04/17[/TD]
[TD="align: center"]01/05/17[/TD]
[TD="align: center"]01/06/17[/TD]
[TD="align: center"]01/07/17[/TD]
[TD="align: center"]01/08/17[/TD]
[TD="align: center"]01/09/17[/TD]
[TD]01/10/17[/TD]
[TD]01/11/17[/TD]
[/TR]
</tbody>[/TABLE]

How do I expand the code to include these and to have a message saying which of the above has expired?

I know it's probably quite simple to do but thought I'd ask.

Thanks

Stephen.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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