Convert formula to Function

Hi,

How to make the following as a Macro Function so I can call it with WeekNo(A1) where A1 would contain the Date...

=IFERROR(INT((DATEDIF((DATE(YEAR(A1),4,6)-WEEKDAY(DATE(YEAR(A1),3,31))-7), A1, "d") / 7))+1,INT((DATEDIF((DATE(YEAR(A1)-1,4,6)-WEEKDAY(DATE(YEAR(A1)-1,3,31))-7), A1, "d") / 7))+1)

Thanks
MirageSFAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Care to share what you think that formula does / what you want the function to do?  Can you share the link to where you got that formula.


»bp
0
MirageSFAuthor Commented:
Hi, it basically calculates number of weeks since last Monday in March of each year, between 1 and 52 or 1 and 53 in some years.
0
MirageSFAuthor Commented:
Infact, I just rewrote the formula and can now achieve the results using...

=1+INT((J2-DATE(YEAR(J2)-(J2<DATE(YEAR(J2), 3,26)),3,26))/7)

But struggling to make it a function!
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Bill PrewIT / Software Engineering ConsultantCommented:
How does that always find the last Monday of March, for any given year?


»bp
0
MirageSFAuthor Commented:
The date in J2 past to it will always be a Monday, the calculation will either use the last Monday as week 1 or first Monday of April as week one, depending on whether its a 52 or 53 week year.
0
Bill PrewIT / Software Engineering ConsultantCommented:
Try this:

Function ElapsWeeks(d As Date) As Integer
    If d < DateSerial(Year(d), 3, 26) Then y = 1 Else y = 0
    If IsDate(d) Then ElapsWeeks = 1 + Int((d - DateSerial(Year(d) - y, 3, 26)) / 7)
End Function

Open in new window


Updated: Changed remaining reference to datIn to d

»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MirageSFAuthor Commented:
Thanks mate, had to change datIN to make it work but now great :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.