Private Sub Workbook_SheetCalculate()
Dim FormulaRange As Range
Dim NotSentMsg As String
Dim MyMsg As String
Dim SentMsg As String
Dim MyLimit As Range
Dim Formulacell2 As Integer
NotSentMsg = "Not Sent"
SentMsg = "Sent"
'Above the MyLimit value it will run the macro
Set MyLimit = ActiveWorkbook.Ranges("D2:D2000")
'Set the range with Formulas that you want to check
Set FormulaRange = ActiveWorkbook.Ranges("C2:C1000")
On Error GoTo EndMacro:
For Each Formulacell In MyLimit.Cells
With Formulacell
If IsNumeric(.Value) = False Then
MyMsg = "Not Numeric"
Else
Formulacell2 = Formulacell.Value
For Each Formulacell In FormulaRange.Cells
With Formulacell
If IsNumeric(.Value) = False Then
MyMsg = "Not Numeric"
Else
If .Value > Formulacell2 Then
MyMsg = SentMsg
If .Offset(0, 1).Value = NotSentMsg Then
Call Mail_small_Text_Outlook
End If
Else
MyMsg = NotSentMsg
End If
End If
Application.EnableEvents = False
.Offset(0, 1).Value = MyMsg
Application.EnableEvents = True
End With
Next Formulacell
End With
Next Forumlacell
ExitMacro:
Exit Sub
EndMacro:
Application.EnableEvents = True
MsgBox "Some Error occurred." _
& vbLf & Err.Number _
& vbLf & Err.Description
End Sub
Sub Mail_small_Text_Outlook()
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Working in Excel 2000-2013
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim rick As String
Dim orrett As String
Dim rng As Range
Set rng = Nothing
On Error Resume Next
'Only the visible cells in the selection
Set rng = Selection.SpecialCells(xlCellTypeVisible)
'You can also use a fixed range if you want
'Set rng = Sheets("YourSheet").Range("D4:D12").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
rick = "rick.@companyname.com"
orrett = "orrett@companyname.com"
strbody = "Hi there" & vbNewLine & vbNewLine & _
"Cell A1 is changed" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"
On Error Resume Next
With OutMail
.To = orrett
.CC = ""
.BCC = ""
.Subject = "Low Inventory Warning"
.Body = strbody
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
F
Bookmarks