VBA Macro

sheetname

New Member
Joined
Feb 19, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
I am trying to create an Excel Macro to remind my self for all customers that have not send any update within 30 days .The code below has this problem:After i open the excel file that is related to this macro code i am testing it by putting a date that is 30 days past from today.When i do this it recognize it and sen the email right in time.The problem is that there are more cases with 30 days ago and it does not recognize them.
Any Help i would appreciate.
Thanks.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A2:A15")) Is Nothing And Target.Count = 1 Then
Application.EnableEvents = False

If Date - Target.Value = 30 Then

Dim Email_Subject As String, Email_Send_From As String, Email_Send_To As String, _
Email_Cc As String, Email_Bcc As String, Email_Body As String
Dim Mail_Object, Mail_Single

Email_Subject = "Reminder"
Email_Send_From = "example@hotmail.com"
Email_Send_To = "example@hotmail.com"
Email_Cc = ""
Email_Bcc = ""
Email_Body = "Please remind customer "

On Error GoTo debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.to = Email_Send_To
.cc = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body & " with ID " & Target.Offset(, 1).Value & " and name " & Target.Offset(, 2).Value
.send
End With

End If
Application.EnableEvents = True
End If
Exit Sub

debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try changing:
VBA Code:
If Date - Target.Value = 30 Then
to
VBA Code:
If Date - Target.Value > 29 Then
 
Upvote 0
Hello ,i tried,same problem,it works only for rows where i put a date to test it but for the others rows no even the condition(>29) is met.
Thanks.
 
Upvote 0
Hello ,i tried,same problem,it works only for rows where i put a date to test it but for the others rows no even the condition(>29) is met.
Thanks.
Put your code in Worksheet_Calculate
Change will only work on value change
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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