VBA to create emails creating blank emails if only 1 row of data

floggingmolly

Board Regular
Joined
Sep 14, 2019
Messages
167
Office Version
  1. 365
Platform
  1. Windows
I have a VBA code to generate emails based off data in the rows. It works as long as there are 2 or more rows of data. If there's only 1 row, it creates the first email but then keeps creating multiple empty emails and I have to force stop the code. Does anyone know how I can fix this issue? Below is the code I am using. Any help would be greatly appreciated.

Code:
Sub CreateMedalEmails()
Dim EApp As Object
Set EApp = CreateObject("Outlook.Application")
Dim EItem As Object
'Dim EApp As Outlook.Application
'Set EApp = New Outlook.Application
'Dim EItem As Outlook.MailItem
'Set EItem = EApp.CreateItem(olMailItem)

Dim RList As Range
Set RList = Range("A3", Range("A3").End(xlDown))
Dim R As Range
For Each R In RList
    Set EItem = EApp.CreateItem(0)
        With EItem
        .To = R.Offset(0, 13)
        .cc = R.Offset(0, 14)
        .Subject = "Medals Monthly Guidance For " & R.Offset(0, 1) & ", " & R.Offset(0, 2)
        .HTMLBody = "<b>" & R.Offset(0, 1) & "</b>" & " has a Current Classification of " & "<b>" & R.Offset(0, 8) & "</b>" & " and a Projected Classification of " & "<b>" & R.Offset(0, 9) & "</b>" & "." & " Leading indicators for this classification include:" & "<br>" & "<br>" _
        & "<li>" & R.Offset(0, 10) & "</li>" _
        & "<li>" & R.Offset(0, 11) & "</li>" _
        & "<li>" & R.Offset(0, 12) & "</li>" _
        & "<br>" & "<br>" & "<br>" _
        & "<b>" & "Station Personnel Action Steps:" & "</b>" & "<br>" & "<br>" _
        & "1.  Access the SPRS (Keyword: MEDALS) the day you conduct the BD.  Review the information pertaining to the SP and ensure you are providing the most current information (do not blindly rely on the indicators listed within this message)." & "<br>" & "<br>" _
        & "2.  Conduct the business discussion with the service provider." & "<br>" & "<br>" _
        & "3.  Enter the BD into CDAS as" & "<b>" & " Category & Type: " & "</b>" & "Business Outlook/Planning - Classification Review" & "<br>" & "<br>" & "<br>" & "<br>" _
        & "Reference the " & "<font color = blue>" & "<a href =https://mysite.sharepoint.com/teams/ICA/OMF/Documents/BDS-130.pdf>" & "BDS-103 " & "</a>" & "</font>" & "for additional information, or the MEDALS SharePoint site -  Keyword: MEDALS, or contact your BSM for assistance."
        
        .Display
End With
Next R
Set EApp = Nothing
Set EItem = Nothing
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
put these 2 lines after Dim R As Range, run again and I think you'll be surprised.

MsgBox RList.Rows.count
Stop

You can take them out and then change one line to this
Set RList = Range("A3", Cells(Rows.count, "A").End(xlUp))

EDIT - corrected the code line
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

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