Hi,

This is actually my first time programming using VBA. I'm writing a code for sending automatic reminder emails from a list of emails. I'm not entireley sure if the logic i'm using is correct. I created thre columns of 1's and 0's in the raw data worksheet to know when it was necessary to send an email. I;m using this statement ** If Str(i, Col(n)) = 1 Then ** to verify whether or not the number in the matrix is actually one. However, I'm not enterily sure that's possible. This is what i have so far:

Sub Job()
Dim EmailSubject As String
Dim EmailBody As String
Dim EmailRcp As String
Dim Str(50000, 7) As String
Dim Col(7) As Integer
Dim i As Integer
Dim n As Integer
Dim r As Integer



Call Init(i, n, Col)

Call LoadData(Col, Str)

r = Worksheets("Data").Range("Q1").Value 'number of rows
i = 1
n = 1

While n <= 7

While i <= r

If Str(i, Col(n)) = 1 Then

EmailBody = Str(i, Col(2)) & "2 year contract is about to end"
EmailSubject = Str(i, Col(2)) & "Notification Contract "
EmailRcp = Str(i, Col(7))

Call Send_Email(EmailSubject, EmailBody, EmailRcp)

Worksheets("Data").Cells(i, Col(n)) = "S"
i = i + 1

Else: Str(i, Col(n)) = 0

i = i + 1

End If
Wend

n = n + 1
i = 1

Wend


MsgBox ("The corresponding emails have been sent")


End Sub
Sub Send_Email(EmailSubject As String, EmailBody As String, EmailRcp As String)

Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "####@####.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "#######"
.Update
End With

With cdomsg
.To = EmailRcp
.From = "####@#####.com"
.Subject = EmailSubject
.HTMLBody = EmailBody
.Send

End With

End Sub
Sub Init(i As Integer, n As Integer, Col() As Integer) 'initialize variables
Col(1) = 2
Col(2) = 4
Col(3) = 12
Col(4) = 13
Col(5) = 14
Col(6) = 15
Col(7) = 18

i = 1
n = 1

End Sub
Sub LoadData(Col() As Integer, Str() As String)

Dim i As Integer
Dim n As Integer
Dim r As Integer


r = Worksheets("Data").Range("Q1").Value '
i = 1
n = 1

While n <= 7

While i <= r
Str(i, n) = Worksheets("Data").Cells(i, Col(n)).Value 'loading data to matrix

i = i + 1
Wend

n = n + 1
i = 1

Wend

End Sub