I have an assignment to count the number of rows which contain specific text and print the value on email.
Public Function First()
Dim Source As Workbook
Dim Var1 As Integer
Dim Var10 As Integer
Dim Source2 As Workbook
Set Source = Workbooks.Open("C:\Users\HP\Desktop\IN INPROG.xlsx")
Var1 = Application.WorksheetFunction.CountIf(Range("M1:M100"), "Orange")
Source.Close SaveChanges:=False
Set Source2 = Workbooks.Open("C:\Users\HP\Desktop\SR INPROG.xlsx")
Var10 = Application.WorksheetFunction.CountIf(Range("M1:M100"), "Orange")
Source2.Close SaveChanges:=False
eTo = "orange@aod.au"
esubject = Format(Date, "d/mmmm/yyyy") & " " & "Weekly Open Incident Reminder"
ebody = "Dear All," & vbCrLf & "" & vbCrLf & "" & vbCrLf & "Orange: " & "SR: " & Var10 & " IN: " & Var1
Set app = CreateObject("Outlook.Application")
Set itm = app.createitem(0)
On Error Resume Next
With itm
.Subject = esubject
.To = eTo
.body = ebody
.display
My code will return all the values as "0" even though "Orange" does exist in one of the rows.