I'm having trouble sending an email after having the user define a "Reorder" level on an inventory project. I have tried troubleshooting or tweaking Ron's http://www.rondebruin.nl/mail/change.htm but i'm currently getting a mismatch error.
If I can define Reorder Level to be Column "P" and my Remaining Inventory to be column "O". I'm trying to use the logic that if my Remaining inventory is lower than my "Reorder" Level (or threshold), an email is generated to send out to me. My Remainging Inventory is a formula and Reorder Level has conditional formatting. Any help would be very beneficial.
Private Sub Worksheet_Calculate()
Dim FormulaRange As Range
Dim NotSentMsg As String
Dim MyMsg As String
Dim SentMsg As String
'Dim Reorder As Double
NotSentMsg = "Not Sent"
SentMsg = "Sent"
'Above the Reorder value it will run the macro
' Reorder = 200
' Remaining Inventory < Reorder Level should trigger the Macro
Dim Reorder As Range
Set Reorder = Me.Range("P9:P80")
'Set the range with Formulas that you want to check
Set FormulaRange = Me.Range("O9:O80")
On Error GoTo EndMacro:
For Each FormulaCell In FormulaRange.Cells
With FormulaCell
If IsNumeric(.Value) = False Then
MyMsg = "Not numeric"
Else
If .Value > Reorder Then
MyMsg = SentMsg
If .Offset(0, 2).Value = NotSentMsg Then
Call Mail_with_outlook2
End If
Else
MyMsg = NotSentMsg
End If
End If
Application.EnableEvents = False
.Offset(0, 2).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
If I can define Reorder Level to be Column "P" and my Remaining Inventory to be column "O". I'm trying to use the logic that if my Remaining inventory is lower than my "Reorder" Level (or threshold), an email is generated to send out to me. My Remainging Inventory is a formula and Reorder Level has conditional formatting. Any help would be very beneficial.
Private Sub Worksheet_Calculate()
Dim FormulaRange As Range
Dim NotSentMsg As String
Dim MyMsg As String
Dim SentMsg As String
'Dim Reorder As Double
NotSentMsg = "Not Sent"
SentMsg = "Sent"
'Above the Reorder value it will run the macro
' Reorder = 200
' Remaining Inventory < Reorder Level should trigger the Macro
Dim Reorder As Range
Set Reorder = Me.Range("P9:P80")
'Set the range with Formulas that you want to check
Set FormulaRange = Me.Range("O9:O80")
On Error GoTo EndMacro:
For Each FormulaCell In FormulaRange.Cells
With FormulaCell
If IsNumeric(.Value) = False Then
MyMsg = "Not numeric"
Else
If .Value > Reorder Then
MyMsg = SentMsg
If .Offset(0, 2).Value = NotSentMsg Then
Call Mail_with_outlook2
End If
Else
MyMsg = NotSentMsg
End If
End If
Application.EnableEvents = False
.Offset(0, 2).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