Auto mailing with conditions - problem with mismatch

MMasiarek

New Member
Joined
Mar 2, 2021
Messages
20
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have two sheets, one with email adresses and date when mail was sent - "Biura_podr".
Another one with with code used for sending emails - "Mail".

In sheet with mail adresses and send dates I have this code, which is checking if email was sent already in this month:
VBA Code:
Public Function Czy_wyslac() As Boolean

    Dim rngEnd      As Range
    Dim rngBeg      As Range
    Dim iCell       As Range
    Dim strSearch   As String
    Dim dtToday As Date
    
    'search range
    Set rngBeg = Range("A1")
    Set rngEnd = Range("A" & Range("A1").End(xlDown).row)
    
    'search value
    strSearch = Sheets("Mail").Range("D3").Value
    
    
    For Each iCell In Range(rngBeg, rngEnd)
        If InStr(iCell.Value, strSearch) Then
            If DateDiff("m", DateValue(iCell.Offset(0, 4).Value), DateValue(Now)) = 0 Then Czy_wyslac = False
            Exit Function
        End If
    Next iCell

End Function

In Sheet I want to use for sending emails I have this code:
VBA Code:
Private Sub Auto_mail()

Dim lista_max As Integer
Dim rng As Range
Dim row As Range
Dim cell As Range
Dim czyWyslac As Boolean

czyWyslac = Sheets("Biura_podr").Czy_wyslac

lista_max = Worksheets("Biura_podr").Range("D2").End(xlDown).row
'MsgBox lista_max

Set rng = Worksheets("Biura_podr").Range("A2:A" & lista_max)

For Each row In rng.Rows
  For Each cell In row.Cells
  
    Worksheets("Mail").Range("$A$3").Value = cell.Value
    Sheets("Biura_podr").Sprawdz_date
    Sheets("Biura_podr").Czy_wyslac

    If czyWyslac = False Then GoTo NextIteration
    'End If

    Sheets("Biura_podr").Uzupelnij_czas

NextIteration:
  Next cell
Next row

End Sub

My idea was to go in the loop through whole email list and check if mail was sent already in this month. If yes function Czy_wyslac() should return false and in Sub Auto_mail() this email shoul be skipped.
What I'am getting is Run-time error '13': Type mismatch.
I cannot find what causes this error, can you assist with this issue?
 

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
I’m not an excel guru, but looking through your coding the application in which you would use to email isn’t identified.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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