VBA code for email body to send a cells value

slickster135

New Member
Joined
Mar 20, 2025
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have this code that works fine but I would like the second email body to have the text that's in cells A2:A52 if any of the cells meet the code of >0 and <30. I am stumped on this one. Thanks for any help someone can offer.



Screenshot 2025-03-20 173949.png
 
Please check, Thank you!
VBA Code:
Sub SendEmailOnOpen()
    Dim ws As Worksheet
    Dim cell As Range
    Dim emailSent As Boolean
    Dim emailAddress As String
    Dim emailSubject As String
    Dim emailBody As String
    Dim textList As String

    emailAddress = "abc@mail.com"
    emailSubject = "Alert: License Renewal"
    emailBody = "One or more licenses are within 30 days or less and require renewal:" & vbNewLine & vbNewLine
    textList = ""

    Set ws = ThisWorkbook.Sheets("License tracker")

    emailSent = False

    For Each cell In ws.Range("L2:L52")
        If cell.Value > 0 And cell.Value < 30 Then
            textList = textList & "- " & ws.Cells(cell.Row, 1).Value & vbNewLine
            emailSent = True
        End If
    Next cell

    If emailSent Then
        emailBody = emailBody & textList

        With CreateObject("Outlook.Application").CreateItem(0)
            .To = emailAddress
            .Subject = emailSubject
            .Body = emailBody
            .Send
        End With
    End If
End Sub
 
Upvote 0

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