PDA

View Full Version : Wrong date VBA



ced0802
12-23-2015, 05:58 AM
Hello everyone,

I would like the date to be Week 01 and not week 54..


Sub totx6in2W()
'Donne la demand de la semaine N+2 en generics x6
Dim db As Workbook
Dim WkStg As String
Dim annee As Long

annee = Year(Date)
annee = Format(Date, "yy")

mois = Month(Date)
jour = Day(Date)
If Len(jour) < 2 Then
jour = "0" & Day(Date)
End If

WkStg = Application.WorksheetFunction.WeekNum(Now(), 2) + 2
Title = "Wk " & WkStg & " Production schedule - " & annee & mois & jour


Thank you very much in advance !

mancubus
12-23-2015, 06:42 AM
hi.

why +2?

try:


Sub vbax_54622_totx6in2W()
Dim Title As String
Title = "Wk " & Format(Date, "ww") & " Production schedule - " & Format(Date, "yymmdd")
End Sub

SamT
12-23-2015, 07:43 AM
Function GetTitle(Optional MyDate As Date)
If MyDate = 0 Then MyDate = Date

WkStg = DateDiff("ww", "1/1/" & Year(DateAdd("ww", 2, MyDate)), (DateAdd("ww", 2, MyDate)))
GetTitle = "Wk " & WkStg & " Production schedule - " & Format(MyDate, "yymmmdd")
End Function



Sub Test1_GetTitle()
MsgBox GetTitle
End Sub


Sub Test2_GetTitle()
MsgBox GetTitle("11-Nov-15")
End Sub

ced0802
12-30-2015, 07:22 AM
Hi,

+2 because I want to work with a file which title includes the current week+2 (we are week 53, title is week 02)
The issue is that it doesn't go to 2016..but Week 54,55 etc..

Bob Phillips
12-30-2015, 07:30 AM
Then maybe you should use


Application.WorksheetFunction.WeekNum(TODAY()+14,2)