I am working with Excel 2010.
I wish to convert a given date from the format mm/dd/yyyy
to the format Wyy"weeknumber"
For example, 4/10/2017
would become W1715
, since it is week 15 of 2017.
The below shown image is of the excel table I am working on. I want to convert the dates in column LT Verification - Planned Date
to the week number format mentioned above, in column LT Verification - Planned Week Numbers
.
Edit: Because this is part of a larger VBA process, I need it to be in VBA, not a cell formula.
I have written the following code:
Public Sub WeekNumbers()
Dim lastRow As Integer
lastRow = Range("A1:AZ1").Find("*", , , , xlByRows, xlPrevious).Row
Dim myRange As Range
Set myRange = Range("A1:AZ1" & lastRow)
Dim myCell As Range
For Each myCell In myRange
myCell.Offset(0, 1).Value = "W" & Right(Year(myCell.Value), 2) & Application.WorksheetFunction.WeekNum(myCell.Value)**
Next myCell
End Sub
This code gives me error at myCell.Offset(0, 1).Value = "W" & Right(Year(myCell.Value), 2) & Application.WorksheetFunction.WeekNum(myCell.Value)
Here I have a excel workbook which will be updated every week. So, each time it is updated, it runs a macro to import data from another file & perform the week number activity & create a pivot table.
So, the sheet name changes every week. Also, the column headers may be in different columns in different weeks. Also, the number of rows may also change every week.
So, I need to specify column & row range dynamically based on that weeks data. And have the week numbers in the column based on the column header rather than the column name (A or B or Z...)