DatePart Function in VBA

E

ExcelMonkey

I am using the VBA DatePart Function as a function in Excel:

Function DatePartFunction(qualfier As String, rng As Date)
DatePartFunction = DatePart(qualfier, rng)
End Function

According to the Help resources, the function takes the following arguments:
DatePart(interval, date[,firstdayofweek[, firstweekofyear]])

How do I incoporate the firstdayofweek and firstweekofyear arguments. For
example in A1 I have the following date: 24/03/2006. Then in B1 I have the
following formula: =DatePartFunction("ww",$A$1) - See list below. The result
in B1 is 6. I am assuming that as 24/03/2006 is a Friday that the 6 must
mean that the first day of the week is assumed to be Sunday. I want to set
the first day of the week to Monday so that the result of the function is 5.
How do I do this in code/Excel? Thanks


yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
 
S

Stefi

=DatePartFunction("w",$A$1,2) is the right usage!
Stefi


„ExcelMonkey†ezt írta:
 
S

Stefi

Function DatePartFunction(qualfier As String, rng As Date, firstdw)
DatePartFunction = DatePart(qualfier, rng, firstdw)
End Function


=DatePartFunction("ww",$A$1,2)
will give you 5

Regards,
Stefi


„ExcelMonkey†ezt írta:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Need some PWA help 0
DatePart Expression 1
datepart returns erroneous week number? 2
datepart function 3
Function for week number 5
datePart Function 2
DatePart function 4
Week 53 and Week 1 from a given date 2

Top