{"id":5500,"date":"2021-11-15T13:06:26","date_gmt":"2021-11-15T13:06:26","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=5500"},"modified":"2021-11-15T13:06:57","modified_gmt":"2021-11-15T13:06:57","slug":"how-to-send-an-email-from-excel-if-certain-conditions-are-me","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/office\/how-to-send-an-email-from-excel-if-certain-conditions-are-me\/20735.html","title":{"rendered":"How To Send An Email From Excel If Certain Conditions Are Me"},"content":{"rendered":"<p>I am looking to write code that will send an out an email automatically if 2 conditions are met in excel. The first condition being, is this a repeat design &#8220;Y or N&#8221; and the second is the number of days shown in another column. The criteria is, if &#8220;Y &amp; over 42 days then send email&#8221; or if &#8220;N and over 14 days then send email&#8221; otherwise do nothing.<\/p>\n<p>I have my repeat design in Col G &amp; Number of days in Col K. I have been trying to adapt the code below that I found online earlier on. Unfortunately, it uses a limit instead of the IF function I would like. It is currently set to send out an email as soon as any number in Col K goes over a 200 day limit, that&#8217;s the bit I would like to change.<\/p>\n<p>Private Sub Worksheet_Calculate()<br \/>\nDim FormulaRange As Range<br \/>\nDim NotSentMsg As String<br \/>\nDim MyMsg As String<br \/>\nDim SentMsg As String<br \/>\nDim MyLimit As Double<\/p>\n<p>NotSentMsg = &#8220;Not Sent&#8221;<br \/>\nSentMsg = &#8220;Sent&#8221;<\/p>\n<p><b>&#8216;Above the MyLimit value it will run the macro<br \/>\nMyLimit = 200<\/b><\/p>\n<p>&#8216;Set the range with Formulas that you want to check<br \/>\nSet FormulaRange = Me.Range(&#8220;K8:K100&#8221;)<\/p>\n<p>On Error GoTo EndMacro:<br \/>\nFor Each FormulaCell In FormulaRange.Cells<br \/>\nWith FormulaCell<br \/>\nIf IsNumeric(.Value) = False Then<br \/>\nMyMsg = &#8220;Not numeric&#8221;<br \/>\nElse<br \/>\nIf .Value &gt; MyLimit Then<br \/>\nMyMsg = SentMsg<br \/>\nIf .Offset(0, 1).Value = NotSentMsg Then<br \/>\nCall Mail_with_outlook2<br \/>\nEnd If<br \/>\nElse<br \/>\nMyMsg = NotSentMsg<br \/>\nEnd If<br \/>\nEnd If<br \/>\nApplication.EnableEvents = False<br \/>\n.Offset(0, 1).Value = MyMsg<br \/>\nApplication.EnableEvents = True<br \/>\nEnd With<br \/>\nNext FormulaCell<\/p>\n<p>ExitMacro:<br \/>\nExit Sub<\/p>\n<p>EndMacro:<br \/>\nApplication.EnableEvents = True<\/p>\n<p>MsgBox &#8220;Some Error occurred.&#8221; _<br \/>\n&amp; vbLf &amp; Err.Number _<br \/>\n&amp; vbLf &amp; Err.Description<\/p>\n<p>End Sub<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":8},"question-category":[53],"question_tags":[],"class_list":["post-5500","question","type-question","status-publish","hentry","question-category-office"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/5500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=5500"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=5500"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=5500"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=5500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}