Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

DatePart Function in VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ExcelMonkey - 21 Mar 2006 11:26 GMT
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
Stefi - 21 Mar 2006 11:49 GMT
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:

> I am using the VBA DatePart Function as a function in Excel:
>
[quoted text clipped - 23 lines]
> n Minute
> s Second
Stefi - 21 Mar 2006 11:49 GMT
=DatePartFunction("w",$A$1,2) is the right usage!
Stefi

„ExcelMonkey” ezt írta:

> I am using the VBA DatePart Function as a function in Excel:
>
[quoted text clipped - 23 lines]
> n Minute
> s Second
Tom Ogilvy - 21 Mar 2006 13:49 GMT
You may want to look at this page as well:

http://www.cpearson.com/excel/weeknum.htm

Signature

Regards,
Tom Ogilvy

> I am using the VBA DatePart Function as a function in Excel:
>
[quoted text clipped - 23 lines]
> n Minute
> s Second
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.