how to convert a week number to a date range

bleeet

Board Regular
Joined
May 11, 2009
Messages
208
Office Version
  1. 2013
Platform
  1. Windows
Hi is it possible in VBA to convert a week number to the date range Monday to Friday that's with in it?

I want to display the range of dates in a cell for example "dec 11 - dec 15" in a cell.
 
Last edited:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Let the given week number is n. The New Year belongs to the 1st week hence you can calculate the date n-1 weeks later. Then you can find what day of week it is, and find dates of Mo and Fr in this week.
 
Upvote 0
Let the given week number is n. The New Year belongs to the 1st week hence you can calculate the date n-1 weeks later. Then you can find what day of week it is, and find dates of Mo and Fr in this week.

can you please provide an example

sorry I don't understand
 
Upvote 0
Place the week number in "A1" , Run code for related Dates (Days Mon to Fri) to show in "B1".
NB:- The code works for the current year.
Code:
[COLOR=navy]Sub[/COLOR] MG13Dec11
 [COLOR=navy]Dim[/COLOR] dt [COLOR=navy]As[/COLOR] Date
 [COLOR=navy]For[/COLOR] dt = DateSerial(Year(Date), 1, 1) To DateSerial(Year(Date), 12, 31)
    [COLOR=navy]If[/COLOR] WeekdayName(Weekday(dt), False, vbSunday) = "Friday" [COLOR=navy]Then[/COLOR]
        c = c + 1
        [COLOR=navy]If[/COLOR] c = Range("A1").Value [COLOR=navy]Then[/COLOR] Range("B1").Value = DateAdd("d", -4, dt) & " - " & dt
    [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR] dt
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Excel 2010
ABC
1Sun Jan 1, 2017
2
31Mon Jan 2, 2017Fri Jan 6, 2017
450Mon Dec 11, 2017Fri Dec 15, 2017
551Mon Dec 18, 2017Fri Dec 22, 2017
652Mon Dec 25, 2017Fri Dec 29, 2017
753Mon Jan 1, 2018Fri Jan 5, 2018
8
9Mon Jan 1, 2018
101Mon Jan 1, 2018Fri Jan 5, 2018
11
1b
Cell Formulas
RangeFormula
B3=DATE(2017,1,1)+1+(A3-1)*7
B10=DATE(2018,1,1)+(A10-1)*7
C3=B3+4



I added this in case someone wanted a solution without VBA.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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
Back
Top