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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

CSmith

Well-known Member
Joined
Jan 13, 2020
Messages
686
Office Version
  1. 365
  2. 2010
  3. 2007
Platform
  1. Windows
  2. Mobile
  3. Web
Try changing:
VBA Code:
If Date - Target.Value = 30 Then
to
VBA Code:
If Date - Target.Value > 29 Then
 

sheetname

New Member
Joined
Feb 19, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
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.
 

CSmith

Well-known Member
Joined
Jan 13, 2020
Messages
686
Office Version
  1. 365
  2. 2010
  3. 2007
Platform
  1. Windows
  2. Mobile
  3. Web
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
 

Watch MrExcel Video

Forum statistics

Threads
1,132,788
Messages
5,655,307
Members
418,188
Latest member
Cas8423606

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
Top