+ Reply to Thread
Results 1 to 6 of 6

Getting VBA to send email based on different cell values in Excel

  1. #1
    Registered User
    Join Date
    06-21-2022
    Location
    United States
    MS-Off Ver
    office 365
    Posts
    2

    Getting VBA to send email based on different cell values in Excel

    So I have attached a table were I have a column of values. I want excel to be triggered to send an email to users when the values get below a certain number. I have found a code that will do this if the number to get below (15, for instance) is the same, but I want some of the values to be different. For instance if all the numbers are in column "C" I want rows 1,2, and 3 to trigger an email when the number gets below 12, but I want rows 4 and 5 to trigger an email when the number gets below 27. The code that I found is this: how do I modify it to add different values?

    Dim xRg As Range
    'Update by Extendoffice 2018/3/7
    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
    Set xRg = Intersect(Range("C1:C3"), Target)
    If xRg Is Nothing Then Exit Sub
    If IsNumeric(Target.Value) And Target.Value < 12 Then
    Call Mail_small_Text_Outlook
    End If
    End Sub
    Sub Mail_small_Text_Outlook()
    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Hi there" & vbNewLine & vbNewLine & _
    "This is line 1" & vbNewLine & _
    "This is line 2"
    On Error Resume Next
    With xOutMail
    .To = "Email Address"
    .CC = ""
    .BCC = ""
    .Subject = "send by cell value test"
    .Body = xMailBody
    .Display 'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothin
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Getting VBA to send email based on different cell values in Excel

    Change the line
    Please Login or Register  to view this content.
    to refer to the full range C1-C5

    Change the line that checks the values so it also checks the row (This will determine the low value)
    Please Login or Register  to view this content.
    You don't have to worry about changes to other cells as these are filtered out earlier.

    You might also need to pass a parameter to the mail proc otherwise you won't know which value has dipped below the min quantity.

  3. #3
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,377

    Re: Getting VBA to send email based on different cell values in Excel

    For example

    Please Login or Register  to view this content.
    Last edited by JEC.; 06-21-2022 at 02:44 PM.

  4. #4
    Registered User
    Join Date
    06-21-2022
    Location
    United States
    MS-Off Ver
    office 365
    Posts
    2

    Re: Getting VBA to send email based on different cell values in Excel

    cytop thank you, it worked perfectly!! I thought I would be able to send it to multiple users by just separating email addresses with a comma, but that didn't work. Do you know how I would be able to do that?

  5. #5
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Getting VBA to send email based on different cell values in Excel

    Multiple addresses are usually separated by semi-colons...
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,377

    Re: Getting VBA to send email based on different cell values in Excel

    Thanks for replying…

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Send email based on Cell value in Excel?
    By bixha in forum Excel General
    Replies: 1
    Last Post: 01-30-2019, 05:08 AM
  2. [SOLVED] Send Email Based on Cell Values
    By weeblegobble in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2018, 12:18 AM
  3. Excel to auto send email based on the text of a cell
    By MTC2016 in forum Excel General
    Replies: 4
    Last Post: 01-11-2017, 01:50 PM
  4. Macro to send an email via Lotus Notes to an employee based upon cell values
    By kodonnell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-02-2015, 12:43 PM
  5. Can I have Excel send an email based on cell contents
    By msche09 in forum Excel General
    Replies: 2
    Last Post: 04-09-2014, 03:51 AM
  6. How to send email from excel using VBA with Cell Range (Including Images) as Email Body
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2014, 05:06 AM
  7. excel send an email based on cell value (Date)
    By Arpanasiaworld in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-26-2013, 07:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1