Error 1004 Application defined or object defined error

  • Thread starter Thread starter Legacy 185509
  • Start date Start date
L

Legacy 185509

Guest
Hi
I am trying to use auto email if value is greater than 0
initial value of cell is 0
here is the code
when I change J3 from 0 to 1 I get this error
Error 1004 Application defined or object defined error
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"
 
    'Above the MyLimit value it will run the macro
    MyLimit = 0
 
    'Set the range with the Formula that you want to check
    Set FormulaRange = Me.Range("J3")
 
    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
Sub Mail_with_outlook1()
'For mail code examples visit my mail page at:
'http://www.rondebruin.nl/sendmail.htm
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strto As String, strcc As String, strbcc As String
    Dim strsub As String, strbody As String
 
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
 
    strto = "abc123@gmail.com"
    strcc = ""
    strbcc = ""
    strsub = "Customers"
    strbody = "Hi Zuber" & vbNewLine & vbNewLine & _
              "The total Customers of all stores this week is : " & Cells(FormulaCell.Row, "J3:J15").Value & _
              vbNewLine & vbNewLine & "Good job"
 
    With OutMail
        .To = strto
        .CC = strcc
        .BCC = strbcc
        .Subject = strsub
        .Body = strbody
        'You can add a file to the mail like this
        '.Attachments.Add ("C:\test.txt")
        .Display    ' or use .Send
        '.Send ' or use .Display
    End With
 
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Last edited by a moderator:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Andrew thank you for replying, I figured out the problem whole code is wrong
Thanks for help
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,448
Members
452,915
Latest member
hannnahheileen

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