Send Second Email When Value Reaches Another Threshold

smythcounty

New Member
Joined
Jul 29, 2021
Messages
42
Office Version
  1. 365
Platform
  1. Windows
I'm wondering if it is possible to trigger a second email when the value of H6 is less than 200000? Like Call Mail_with_outlook2. Currently when the value of H6 is less than 400000 it runs the Macro.

Thanks

VBA Code:
Private Sub Worksheet_Calculate()
    Dim FormulaRange As Range
    Dim NotSentMsg As String
    Dim MyMsg As String
    Dim SentMsg As String
    Dim MyLimit As Double
   

    NotSentMsg = "Not Sent"
    SentMsg = "Sent"
    MyLimit = 400000
    Set FormulaRange = Me.Range("H6")

    On Error GoTo EndMacro:
    For Each FormulaCell In FormulaRange.Cells
        With FormulaCell
            If IsNumeric(.Value) = False Then
                MyMsg = "Not numeric"
            Else
                If .Value < MyLimit Then
                    MyMsg = SentMsg
                    If .Offset(0, 1).Value = NotSentMsg Then
                        Call Mail_with_outlook1
                    End If
                Else
               
                    MyMsg = NotSentMsg
                End If
           
            End If
            Application.EnableEvents = False
            .Offset(0, 1).Value = MyMsg
            Application.EnableEvents = True
        End With
    Next FormulaCell

ExitMacro:
    Exit Sub

EndMacro:
    Application.EnableEvents = True

    MsgBox "Some Error occurred." _
         & vbLf & Err.Number _
         & vbLf & Err.Description

End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi, I updated the code to run a separate If statement in the loop when the value is less than 200k. This will generate a 2nd email.

VBA Code:
Option Explicit

Private Sub Worksheet_Calculate()
    Dim FormulaRange As Range
    Dim NotSentMsg As String:
    Dim MyMsg As String
    Dim SentMsg As String:
    Dim MyLimit As Double
    
    NotSentMsg = "Not Sent"
    SentMsg = "Sent"
    MyLimit = 400000:
    Set FormulaRange = Range("H6")

    On Error GoTo EndMacro:
    For Each FormulaCell In FormulaRange.Cells
        With FormulaCell
            If IsNumeric(.Value) = False Then
                MyMsg = "Not numeric"
            ElseIf .Value < MyLimit Then
                MyMsg = SentMsg
                If .Offset(0, 1).Value = NotSentMsg Then
                    Call Mail_with_outlook1
                End If
            Else
                 MyMsg = NotSentMsg
                 Range("C1").Value = MyMsg
            End If
             
            If .Value < 200000 Then
                    Call Mail_with_outlook1
            End If

            Application.EnableEvents = False
            FormulaCell.Offset(0, 1).Value = MyMsg
            Application.EnableEvents = True
        End With
    Next FormulaCell
ExitMacro:
    Exit Sub

EndMacro:
    Application.EnableEvents = True

    MsgBox "Some Error occurred." _
         & vbLf & Err.Number _
         & vbLf & Err.Description
End Sub
 
Upvote 0
Hi, I updated the code to run a separate If statement in the loop when the value is less than 200k. This will generate a 2nd email.

VBA Code:
Option Explicit

Private Sub Worksheet_Calculate()
    Dim FormulaRange As Range
    Dim NotSentMsg As String:
    Dim MyMsg As String
    Dim SentMsg As String:
    Dim MyLimit As Double
   
    NotSentMsg = "Not Sent"
    SentMsg = "Sent"
    MyLimit = 400000:
    Set FormulaRange = Range("H6")

    On Error GoTo EndMacro:
    For Each FormulaCell In FormulaRange.Cells
        With FormulaCell
            If IsNumeric(.Value) = False Then
                MyMsg = "Not numeric"
            ElseIf .Value < MyLimit Then
                MyMsg = SentMsg
                If .Offset(0, 1).Value = NotSentMsg Then
                    Call Mail_with_outlook1
                End If
            Else
                 MyMsg = NotSentMsg
                 Range("C1").Value = MyMsg
            End If
            
            If .Value < 200000 Then
                    Call Mail_with_outlook1
            End If

            Application.EnableEvents = False
            FormulaCell.Offset(0, 1).Value = MyMsg
            Application.EnableEvents = True
        End With
    Next FormulaCell
ExitMacro:
    Exit Sub

EndMacro:
    Application.EnableEvents = True

    MsgBox "Some Error occurred." _
         & vbLf & Err.Number _
         & vbLf & Err.Description
End Sub

It runs without error but doesn't run the macro when <200000. Trying to figure out how you got C1 in this line
MyMsg = NotSentMsg
Range("C1").Value = MyMsg

Thanks for helping me with this.
 
Upvote 0
Oh I was testing and needed to see how your code was working. Remove that line, it's not needed. Sorry about that.
 
Upvote 0
It is still not sending the second email when the value is less than <2000000. I think is has something to do with the MyMsg not being reset at some point before?
 
Upvote 0
Paste your new code, I think you said 200,000 before, that looks like 2,000,000. MyMsg is ignored in the new if statement, it's only looking at the 200,000 value.
 
Upvote 0
Sorry that was a typo, it is 200,000.

VBA Code:
Option Explicit

Private Sub Worksheet_Calculate()
    Dim FormulaRange As Range
    Dim NotSentMsg As String
    Dim MyMsg As String
    Dim SentMsg As String
    Dim MyLimit As Double
    

    NotSentMsg = "Not Sent"
    SentMsg = "Sent"
    MyLimit = 400000
    Set FormulaRange = Me.Range("H7")

    On Error GoTo EndMacro:
    For Each FormulaCell In FormulaRange.Cells
        With FormulaCell
            If IsNumeric(.Value) = False Then
                MyMsg = "Not numeric"
            Else
                If .Value < MyLimit Then
                    MyMsg = SentMsg
                    If .Offset(0, 1).Value = NotSentMsg Then
                        Call Mail_with_outlook1
                    End If
                Else
                    MyMsg = NotSentMsg
                End If
            
            End If
            Application.EnableEvents = False
            .Offset(0, 1).Value = MyMsg
            Application.EnableEvents = True
        End With
    Next FormulaCell

ExitMacro:
    Exit Sub

EndMacro:
    Application.EnableEvents = True

    MsgBox "Some Error occurred." _
         & vbLf & Err.Number _
         & vbLf & Err.Description

End Sub
 
Upvote 0
Hmmm,

That doesn't look like what I posted, you are missing the:

VBA Code:
            If .Value < 200000 Then
                    Call Mail_with_outlook1
            End If

The above is what tells it to email no matter what when less than 200,000
 
Last edited:
Upvote 0
Hmmm,

That doesn't look like what I posted, you are missing the:

VBA Code:
            If .Value < 200000 Then
                    Call Mail_with_outlook1
            End If

The above it what tells it to email no matter what when less than 200,000
I may have lost it in the copy / paste. Let me try it again with that.
 
Upvote 0
I don't know what happened with that. It appears to be working now. I'll keep testing. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,049
Members
449,206
Latest member
Healthydogs

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