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:

1011121314151617181920
H&S 1H&S 2H&S 3H&S 4H&S 5H&S 6 H&S 7H&S 8H&S 9 Insurance - PublicInsurance - Employer
01/01/1701/02/1701/03/1701/04/1701/05/1701/06/1701/07/1701/08/1701/09/1701/10/1701/11/17

<tbody>
</tbody>

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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,216,057
Messages
6,128,524
Members
449,456
Latest member
SammMcCandless

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