IF formula to include certain rows of table in Email body

OllieHiggins

New Member
Joined
Apr 27, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi - I have an action tracker that I want to send out to the action owners. I want to make them aware of their entire actions (even the ones that are not yet due) by attaching the file itself to the email, but i also want to highlight the overdue actions in the body of the email.

I have used the RangetoHTML code from Ron de Bruin's site, but to be honest I don't really follow it, so wonder if it might be something to do with that?

Anyway, my current code is as below. This generates the email, attaches the file and copies the table into the body of the email as it is in the workbook. The missing piece is isolating only the overdue actions in the body.

VBA Code:
Dim emailApplication As Object
Dim emailItem As Object
Dim str1, str2 As String

Set emailApplication = CreateObject("Outlook.Application")
Set emailItem = emailApplication.CreateItem(0)

str1 = "<BODY style = font-size:12pt;font-family:Calibri>" & _
"Hi,<br/><br/> email body. <br>"

str2 = "<br> Thanks, <br>"

Set StatusCol = Range("T7:T200")

On Error Resume Next

    With emailItem
        .To = Range("P7").Value
        .Subject = "Internal Audit Action(s) Follow Up " & Format(Date, "dd/mm/yy")
        .Attachments.Add ActiveWorkbook.FullName
        .HTMLBody = str1 & RangetoHTML(Range("I6:L200")) & str2 & emailItem.HTMLBody
        .Display

    End With
        
    On Error GoTo 0
    Set emailItem = Nothing
    Set emailApplication = Nothing

I had tried to put in an IF formula into this, but it didn't seem to change anything strangely. Still generated the email, but with all rows, regardless of overdue status (i defined Status and StatusCol as Range)

VBA Code:
With emailItem
        .To = Range("P7").Value
        .Subject = "Internal Audit Action(s) Follow Up " & Format(Date, "dd/mm/yy")
        .Attachments.Add ActiveWorkbook.FullName
        
    End With
        
        For Each Status In StatusCol
        If Status = "Overdue" Then
        emailItem.HTMLBody = str1 & RangetoHTML(Range("I6:L200")) & str2 & emailItem.HTMLBody
        
        End If
        Next Status
        
        emailItem.Display
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,214,812
Messages
6,121,696
Members
449,048
Latest member
81jamesacct

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