Send an e-mail based on the number of days until due

Even

Board Regular
Joined
Jan 1, 2013
Messages
81
Office Version
  1. 365
Platform
  1. Windows
Hi there, is it a way to generate an e-mail that includes the text I show beneath? When it is less den 90 days until renewal, I want to send out an e-mail to the person in charge of the customer about the renewal terms.

Send an automatic e-mail based on due date.xlsx
ABCDEFGHIJKLMNOPQR
15/17/2021
2General terms%Special termsCustomerDue dateTime until dueTransportD&OCyberCrimeArtName in chargeE-mail
3Transport4,50%5,00%Example 19/1/211074,50%3,50%5,00%
4D&O3,50%5,00%Example 211/30/211975,00%3,50%
5Cyber3,50%5,00%Example 37/1/21454,50%5,00%JohnJohn@test.com
6Crime3,50%5,00%Example 48/25/211005,00%5,00%
7Art3,50%5,00%Example 56/1/21154,50%3,50%5,00%JaneJane@test.com
8Example 67/30/21745,00%3,50%Jasonjason@test.com
9Example 77/1/21454,50%5,00%LydiaLydia@test.com
10Example 88/1/21765,00%5,00%EllenEllen@test.com
11Example 98/1/21763,50%
12Example 108/1/21763,50%
13
14
15Email SubjectRenewal
16Email BodyDear… it is soon time for renewal for X customer. The following standard terms of renewal is: Transport : 4,5% D&O: 3,5% Crime: 5% Please let me know if they will be renewing under these terms. Thank you! Sincerely X
17
All products
Cell Formulas
RangeFormula
A1A1=TODAY()
I3,I9,I7,I5I3=$B$3
L3,L10,L6:L7L3=$C$6
J3,J7J3=$B$4
J4,J10,J6,J8J4=$C$4
M4,M8M4=$B$7
K5,K9K5=$C$5
H3:H12H3=G3-$A$1
J11J11=B4
J12J12=B4
Cells with Data Validation
CellAllowCriteria
E3:E12List=$A$9:$A$11
 
Thanks. Yes, I need to read up on the second part with double clicking.
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I am a little confused if I can incorporate that into my file, and it might a lot of clicking. Besides, I think I have come up with a better idea. Also, I need a better way of checking if a mail is actually sent and by whom. What if I add two more columns including if the mail has been sent and by whom. In F1 I have a code that shows the customers Patrick and Cathy have. If there is a way to send mail to those customers that have a blank cell in column O that might be a good solution.
 
Upvote 0
I forgot to attach the file:
Send an automatic e-mail based on due date.xlsm
ABCDEFGHIJKLMNOPQRS
15/19/2021All
2General terms%Special termsCustomerDue dateTime until dueTransportD&OCyberCrimeArtMail sendtColleague who sent mailName in chargeE-mail
3Transport4,50%5,00%Example 18/1/21744,50%3,50%5,00%OkPatrickJohnJohn@test.com
4D&O3,50%5,00%Example 28/2/21755,00%3,50%CathyJohnJohn@test.com
5Cyber3,50%5,00%Example 38/3/21764,50%5,00%PatrickJohnJohn@test.com
6Crime3,50%5,00%Example 48/4/21775,00%5,00%OkCarterJaneJane@test.com
7Art3,50%5,00%Example 58/5/21784,50%3,50%5,00%OkLeAnneJaneJane@test.com
8Example 68/6/21795,00%3,50%OkPatrickJasonjason@test.com
9Example 78/7/21804,50%5,00%LeAnneLydiaLydia@test.com
10Example 88/8/21815,00%5,00%OkCathyEllenEllen@test.com
11Example 98/9/21823,50%CarterEllenEllen@test.com
12Example 108/10/21833,50%CarterEllenEllen@test.com
All products
Cell Formulas
RangeFormula
A1A1=TODAY()
I3,I9,I7,I5I3=$B$3
L3,L10,L6:L7L3=$C$6
J3,J7J3=$B$4
J4,J10,J6,J8J4=$C$4
M4,M8M4=$B$7
K5,K9K5=$C$5
H3:H12H3=G3-$A$1
J11J11=B4
J12J12=B4
Cells with Data Validation
CellAllowCriteria
E3:E12List=$A$9:$A$11
F1List=$A$24:$A$26
 
Upvote 0
I also tried to change the cell color in column O based on the value. If it is "Ok", "Wait" or Blank. I use the following code, but it doesn't work. What do I wrong?
VBA Code:
Sub color()
Dim color As Integer
For Each cell In Sheets("All products").Range("O3:O500")

If cell.Value = "Ok" Then color = 3
If cell.Value = "Wait" Then color = 4
Else: color = 2


End If
Range(Cells(cell.Row, 15)).Interior.color = RGB(color)



End Sub
 
Upvote 0
We'll start with the color first. The color variable is a Long (as opposed to Integer) type with values between 0 and 16,777,216. 0 is black and 16,777,216 is white. The numbers in between are the rest of the colors.

This Long number can be generated by the RGB function if you know how much red, green, and blue you want to have for a color. You send to the RGB function a red value, a blue value, and a green value, all of these between 0 and 255. In the end, however, you end up with a Long value calculated from the individual components.

Apart from syntax errors in your code, it IS perfectly fine to set the colors to 2, 3, or 4; however, you would never tell the difference between these BLACK shades by eye. (0 is all black, and 2-4 are so very close when compared with the entire range up to 16,777,216).

The trick is to get the number of the color you want. This code below will print in the Immediate Window of the VB editor the interior color number of the active cell. Take any cell in the worksheet and manually change its color to the one you want. Then, put this code into a module, make sure the Immediate Window is showing (Ctrl + G, or View->Immediate Window), make sure the active cell in the spreadsheet is the one with the color, and run it. The Immediate Window will show the current color both as a Long and as an RGB conversion. You can then use either one to set the color in your code. Run this for each different color you want: since you have Ok and Wait, you might want 2 colors while the rest are white.

VBA Code:
Sub PrintRGBFromLong()
    Dim longColor As Long
    Dim rgb As String
    
    longColor = ActiveCell.Interior.color
    rgb = "RGB("
    'get R
    rgb = rgb & CStr(longColor Mod 256) & ", "
    'get G
    rgb = rgb & CStr((longColor \ 256) Mod 256) & ", "
    'get B
    rgb = rgb & CStr((longColor \ 65536) Mod 256) & ")"
    Debug.Print "Interior color as long: " & longColor
    Debug.Print "Interior color as RBG: " & rgb
End Sub

Once you have the number values of the colors you want, you can put them into the code for the Ok and Wait colors in the "color" procedure:
VBA Code:
Sub color()
    Dim OkColor As Long
    Dim WaitColor As Long
    Dim NoColor As Long
    
    OkColor = ??
    WaitColor = ??
    NoColor = 16777215 'Color for white
    'or NoColor = rgb(255, 255, 255)
    
    For Each cell In Sheets("All products").Range("O3:O500")
        If cell.Value = "Ok" Then
            cell.Interior.color = OkColor
        ElseIf cell.Value = "Wait" Then
            cell.Interior.color = WaitColor
        Else
            cell.Interior.color = NoColor
        End If
    Next
End Sub
 
Upvote 0
For your "email sent and by whom" issue, I have a lot of questions that I think would need to be answered to start completing the functionality of sending and logging the emails.

How do Ok and Wait relate to column O? Is the code supposed to put Ok into the cell if the message is sent? If the email is only displayed and not automatically sent by the VBA code, do you want to have the code put Ok into the cell anyway, even if the sender can cancel sending the email?

How do you want Excel to determine who is actively using the spreadsheet? It should be possible to determine the user of Outlook but additional parsing will probably be necessary to get "Patrick" from the mailbox details. Is the code supposed to prohibit LeAnn from sending emails to Patrick's customers? What does F1 contribute to the list of users in column P?
 
Upvote 0
Wow. That was an amazing color lecture. Super thanks! But do I have to create a box to active the code? The background color won't change automatically as I type?
 
Upvote 0
Regarding your questions: I was thinking that me and my colleagues manually write down in column O and P as we go along. So it is not going to be foolproof, but it might help us to have a system if we we follow it. The F1 is a dropdown list where my colleagues can choose a name and all their customers that they are in charge of come up. And it will display if they have sent an e-mail or not. If they haven't sent mail, the cells in column O is blank. When they click the button/box that says send mail it will generate a mail with the relevant info displayed and ready to click send for those customers that have shorter than 90 days until due AND has a blank cell i column O. Just like the code you made before. But that generated an e-mail for all cells where the due date was shorter than 90 days. Example: When Patrick clicks on his name in F1 his three customers comes up: Two he already sent mail to (it says Ok in column O) and one that needs to send to (blank cell in column O). So when Patrick clicks on the send mail box, only one mail is generated.
I hope this made it a little bit clearer.
 
Upvote 0
But do I have to create a box to active the code? The background color won't change automatically as I type?
I'm not sure what you mean by creating a box or automatically typing anything.

Take a cell in col P that you want to make a color for Ok. Manually add the color to the cell through the menu option. Then, with that cell selected, go to the PrintRGBFromLong macro and run it.
 
Upvote 0
So you want the code to check col P to make sure it matches the F1 value (their name) and to also see if col O is blank before creating the email?
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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