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:
In Sheet I want to use for sending emails I have this code:
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?
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?