0

I have an excel vba sub that sends email reminders every 14 days based on a date in a cell. I would also like to include the week number since the date in the cell to todays date. E.g. Cell date 1st April to present day 28th April to return 4 weeks. Please can someone help.

Sub SalesProgress14()
'
' 14 Day Sales Chase Loop
'
'Dim Answer As VbMsgBoxResult
'Answer = MsgBox("Are you sure you want to run?", vbYesNo, "Run Macro")
'If Answer = vbYes Then

Dim i As Integer, Mail_Object, Email_Subject, o As Variant, lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row

Dim saledate As String

Set Mail_Object = CreateObject("Outlook.Application")
For i = 2 To lr
    With Mail_Object.CreateItem(o)
        .Subject = "Sales Chase" & Range("S" & i).Value & " " & Range("U" & i).Value & " " & Range("G" & i).Value
        .To = "test@test.com"
        .Body = Range("S" & i).Value & " " & Range("U" & i).Value & " " & Range("G" & i).Value
        '.display
        ' Our data below
        saledate = Range("F" & i).Value

' Send logic

If DateDiff("d", saledate, Date) Mod 14 = 0 Then .Send

If saledate = Date - 7 Then .Send

End With
Next i
    'MsgBox "E-mails successfully sent", 64
    'Application.DisplayAlerts = False
Set Mail_Object = Nothing

' The End If below relates to the run yes or no box
'End If

End Sub
Paul C
  • 15
  • 4

2 Answers2

0

use

DateDiff("w", saledate, Date) 
DisplayName
  • 13,283
  • 2
  • 11
  • 19
0

You could use ISOWEEKNUM

Public Sub Test()
  Dim saleDate As Date, currDate As Date
  saleDate = "2018-04-01"
  currDate = "2018-04-28"

  Debug.Print Application.WorksheetFunction.IsoWeekNum(currDate) - Application.WorksheetFunction.IsoWeekNum(saleDate)

End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101