Link to home
Start Free TrialLog in
Avatar of Mehawitchi
Mehawitchi

asked on

Get Actual Date from Day of Week & Week Number

Hello Experts,

The attached VBA formula will give you the week number based on two variables (First day of the year and a given date): (Note that Starting day of the year is hard-coded in the formula)

What I need to do is actually to reverse this formula, i.e. to supply week number and Day of week (Sat, Sun, Mon,...Fri) and I get the corresponding date to that day.

For exaple, if I want to know what the date corresponding to Saturday on week 12, the function call will look like the following:

Dim myDate as Date

myDate = GetDate("Sat", 12)
 
Thank you for your help

Function FiscalWeek(aDate As Date) As Long

Dim yearStart As Date
Dim dayGap As Long, wCount As Long

yearStart = DateSerial(2010, 9, 18)
dayGap = aDate - yearStart

FiscalWeek = Int(dayGap / 7) + 1

End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mehawitchi
Mehawitchi

ASKER

Solution by rorya is working 100%
Solution by  peter57r has a small bug:
"Nz" was not recognized by the VBA compiler and the function halted there, but I appreciate the effort
Nz is an Access function and will work there (but not elsewhere).
I'm using this function in Excel - That's why.

Thanks for clarifying
True- I was conscious of it but forgot to change the code in the end.  I made the comment about validating the day, because I knew that nz would not be available-  - but anyway, you have a working solution.