Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default DatePart Function in VBA

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default DatePart Function in VBA

=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:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default DatePart Function in VBA

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:

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default DatePart Function in VBA

You may want to look at this page as well:

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

--
Regards,
Tom Ogilvy


"ExcelMonkey" wrote:

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Datepart problem Ron Dean Excel Programming 7 January 6th 06 03:04 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM


All times are GMT +1. The time now is 03:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"