繁体   English   中英

Excel VBA从单元格日期计算星期数并显示

[英]Excel VBA to calculate week number from cell date and display

我有一个Excel VBA子,它根据单元格中的日期每14天发送一次电子邮件提醒。 我还想包括从单元格中的日期到今天的日期的星期数。 例如,Cell日期从4月1日到4月28日,返回4周。 请有人帮忙。

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

采用

DateDiff("w", saledate, Date) 

您可以使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM