Send a single e-mail to multiple recipients if certain cell is not populated with a value

mikenelena

Board Regular
Joined
Mar 5, 2018
Messages
139
Office Version
  1. 365
Platform
  1. Windows
I have a list of e-mail addresses in column D. Column B populates from a query as mileage reports are received from employees. Until a report is received and captured by the query, the cell shows "#N/A" (A VLookup with no result yet.)

I would like to send a single e-mail reminder to all employees that have not submitted a mileage report.

This is what I am working with so far. The line in red captures ALL the e-mail addresses, and needs to change, but to what? I'm guessing an "If" statement, but can't craft it properly.

Code:
Public Sub Mail_Workbook_1Click()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim EmailTo As String
    Dim BCCTo As String
    Dim strbody As String
    
[COLOR=#ff0000]    BCCTo = Join(Application.Transpose(Worksheets("MileageReports").Range("D5:D26").Value), ";")[/COLOR]
        
    strbody = "****** style=font-size:11pt;font-family:Calibri>Your mileage report is overdue." </BODY>"


    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(olMailItem)
    
    
    On Error Resume Next
            With OutMail
                    .Display
                     .BCC = BCCTo
                    .Subject = "Mileage Reports Due"
                    .HTMLBody = strbody & "<br>" & .HTMLBody
                                        
            End With
    
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing


End Sub

Any help would be most appreciated!

Thanks,
...Mike
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You cannot use JOIN to get all the due addresses, but need a loop. Try replacing your JOIN line with this code:
Code:
With Worksheets("MileageReports")
    For i = 5 To 26
        If IsError(.Cells(i, "B")) Then
            BCCTo = BCCTo & .Cells(i, "D") & "; "
        End If
    Next i
End With
BCCTo = Left(BCCTo, Len(BCCTo) - 2)
Bye
 
Last edited:
Upvote 0
Thanks for your response Anthony. That code is throwing an invalid procedure error on the last line.
Code:
[COLOR=#333333]BCCTo = Left(BCCTo, Len(BCCTo) - 2)[/COLOR]
I'm not sure what this line does exactly, so it's difficult to know how to tweak it. Can you point me the right way?

Thanks!
 
Upvote 0
Thanks for your response Anthony. That code is throwing an invalid procedure error on the last line.
Code:
[COLOR=#333333]BCCTo = Left(BCCTo, Len(BCCTo) - 2)[/COLOR]
I'm not sure what this line does exactly, so it's difficult to know how to tweak it. Can you point me the right way?

Thanks!
In responding to your point I forgot to consider that it is absolutely possible that everybody was on time and nothing is overdue...
Replace the instruction BCCTo = Left(BCCTo, Len(BCCTo) - 2) with
Code:
If Len(BCCTo) > 4 Then
    BCCTo = Left(BCCTo, Len(BCCTo) - 2)
Else
    MsgBox ("No any report is overdue")
    Exit Sub
End If
Bye
 
Upvote 0
Anthony,

Thanks so much, that worked perfectly... I greatly appreciate your help!!!
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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