+ Reply to Thread
Results 1 to 5 of 5

Send Email Based on Cell Value

  1. #1
    Registered User
    Join Date
    11-13-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    12

    Send Email Based on Cell Value

    Hi everyone,

    The below VBA code is set to send an email to a recipient (in column J) whenever a "Yes" is entered in column "I:I".
    The issue is that if I put "Yes" in I3 and there is already a "Yes" in I2, it will send two emails for the two lines. If I now put "Yes" in I4, it will send an email to I2, I3 AND I4.

    I'd like my code to only send an email to the line I am putting a "Yes" in.

    Thanks!

    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. I have also added indentation because the undindented code was nearly unreadable. --6StringJazzer
    Last edited by 6StringJazzer; 11-13-2018 at 12:05 PM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Send Email Based on Cell Value

    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Your problem is that wile a worksheet change event is triggering the call to mail_small_text, that sub is looping through all of column I to decide who to email. You need to pass a range "Intersect(Target, Range("I:I"))" to the sub, and then only loop through that.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,848

    Re: Send Email Based on Cell Value

    Welcome to the Forum M5B!

    I added code tags for you, plus indentation. However, the code does not compile. There is an error on the line in red due to unbalanced quotes.

    I correct that error and made the change you are asking for, but I cannot test it without your file.

    The strategy is to make xCell an argument to the Sub since Worksheet_Change already knows which cell changed. Then you no longer need the loop to check every cell for "Yes".
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    11-13-2018
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    12

    Re: Send Email Based on Cell Value

    Thanks Arkadi and 6StringJazzer.

    I knew there was a redundant part somewhere but could not figure out how to fix it!
    Now it works perfectly

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,848

    Re: Send Email Based on Cell Value

    The code can be pruned down a bit more. I removed other parts that are no longer needed.


    Please Login or Register  to view this content.

+ 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 Values
    By weeblegobble in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2018, 12:18 AM
  2. 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
  3. Workflow with signatures (if cell=x then send email, if signed then send email)
    By Kate2811 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2014, 05:37 AM
  4. Send email to address based on cell value
    By shiftyspina in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2014, 03:06 PM
  5. Send email based on address in a cell
    By behnam in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-19-2013, 02:53 PM
  6. 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
  7. send an email based on data in specific cell
    By savage in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2010, 11:54 AM

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