Send auto email based on two factors, date falls within 90days & cell value B6

hsolanki

Board Regular
Joined
Jan 16, 2020
Messages
204
Office Version
  1. 2010
Platform
  1. Windows
Good Morning all

i was wondering if anyone could help me. i have got a code that works fine based on the "B6" value however i now want to add an also if the value changes and it is within the 90 days (date value its in range E column.

below it is the code whereby i get an error run time error '13'

VBA Code:
Dim SentMsg As String

Dim r As Range, cell As Range
Set r = Range("E3:E10000")

On Error GoTo errHandler:
Sheet3.Unprotect Password:="Bhaji2020"

NotSentMsg = "Not Sent"
SentMsg = "Sent"
    For Each cell In r
With Me.Range("B6")
    If Not IsNumeric(.Value) Then
        MyMsg = "Not numeric"
    Else

         If r.Value <= (Date - 90) And .Value > 15 And .Value < 30 Or .Value > 63 And .Value < 73 Or .Value > 124 Then
            MyMsg = SentMsg
            If .Offset(0, 1).Value = NotSentMsg Then
                Call Mail_Outlook_With_Signature_Html_1
                MsgBox "Email has been sent", vbInformation
            End If
        Else
            MyMsg = NotSentMsg
        End If
    End If
    Application.EnableEvents = False
    .Offset(0, 1).Value = MyMsg
    Application.EnableEvents = True
End With

Application.EnableEvents = True
Sheet3.Protect Password:="Bhaji2020", DrawingObjects:=False, Contents:=True, Scenarios:= _
        True

On Error GoTo 0
Exit Sub
errHandler:
MsgBox "An Error has Occurred  " & vbCrLf & _
       "The error number is:  " & Err.Number & vbCrLf & _
       Err.Description & vbCrLf & "Please Contact Admini"
Next
End Sub
 
the code in the workbook you just attached does not match what I sent earlier. Try doing a copy/paste to ensure it is all updated.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi Candyman thanks.

i have tried all your codes and it keeps sending an email out.

i am going crazy, i have gone blind i would appreciate if you could see on the revised V1 sample where i am going wrong as i cant seem to know now
 
Upvote 0
I'm not sure what to tell you at this point. When I run it, It definitely doesn't send email beyond the list in the log details tab.

It would probably be helpful for you to document in detail what you want each of the formulas to do. I suspect your formula in column J is incorrect....and maybe that's why it doesn't do what you want it to do?

Staff Sample File.xlsm
ABCDEFGHIJ
1Audit Trail / Track History
2Sheet & Cell ReferencesOld ValueNew ValueUserDate & Time Cell Number505125
32022 - L16:W27HSolanki08-08-2022Sent
42022 - H15SHSolanki09-09-2021Sent
52022 - O25SHSolanki10-10-2022Not Sent
62022 - V23SHSolanki04-11-2021Sent
72022 - H15SSjoe04-11-2022Not Sent
82022 - AA29Sjoe07-11-2022Not Sent
9
10
11
12
13
LogDetails
Cell Formulas
RangeFormula
G2G2=SUMPRODUCT(LEN(C3:C99983)-LEN(SUBSTITUTE(C3:C99983,"S","")))
H2H2=SUMPRODUCT(LEN(C3:C99983)-LEN(SUBSTITUTE(C3:C99983,"s","")))
I2I2=SUM(G2:H2)
J2J2=I2*G2*G2
 
Upvote 0
Morning Candyman

thanks, Cell number J2 is correct that works according to our company policy, and the numbers are correct. basically, it will add all Capital S & small S and then the total number of S is multibuy the small S twice which will give you a number that is recorded on cell number J2.

what I would like to do then is that when cell J2 is between the two set values it needs to send an email based on the between the two-value set and if the dates in 3 months comparing somehow when the last email was sent now I am not too sure if this is possible to achieve
 
Upvote 0
If I understand correctly you’re close. And I’m sure it is achievable. Rather than have sent/ not sent in column F you should have the date the email was sent. Then when looking at your date and number evaluations in VBA use the sent date rather than the audit log change date.
 
Upvote 0
Hi Candyman thanks, would you be able to help me with that how to put that together
 
Upvote 0
I can but I’m out of the office today and don’t have access to a computer. I’ll touch base tomorrow
 
Upvote 0
Hi Candyman no problem whenever you get a chance, i do appreciate for all your help :)
 
Upvote 0
Give this a try. I left a bunch of your code in there and just commented out what isn't needed. Once you're good with the functionality you can clean it up as desired.

 
Upvote 0
Hi Candyman thanks for pulling the codes together for me however what it is doing is that once the date is within the past 90 days and the set value is reached in cell number K2 it will send multi emails for all those cells the date was not entered, and it is also bypassing the mgs Not Sent / Sent cell in L2.

i only require sending 1 email if the date is within the past 90 days from the last email sent against Capital S in column C and the set value is reached in cell number K2 and then only to send email based on this
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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