Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default calculate weekdays only

On Tue, 21 Sep 2004 13:55:02 -0700, "benb"
wrote:

I am looking for code to insert yesterday's date if yesterday was a weekday,
and to use the previous Friday's date otherwise (if yesterday was Sunday).
Anyone know how to do this? Thanks.


Some more thoughts:

If you don't have/don't want to have the ATP installed, I believe this formula
will work:

=A1-1-WEEKDAY(A1)*(WEEKDAY(A1)<3)

If you want it as a UDF, you can implement the same function in code:

=============
Function PrevWD(dt As Date) As Date
PrevWD = dt - 1 + Weekday(dt) * (Weekday(dt) < 3)
End Function
=============

Note that in code you have to reverse the sign of the weekend adjustment due to
the way that VBA handles booleans.


--ron
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
Weekdays Kerryn Excel Discussion (Misc queries) 7 July 5th 08 01:56 AM
calculate weekdays only Mike Excel Programming 2 September 21st 04 11:09 PM
calculate weekdays only Ron Rosenfeld Excel Programming 0 September 21st 04 11:05 PM
calculate weekdays only Tom Ogilvy Excel Programming 0 September 21st 04 10:19 PM
Calculate weekdays from two dates JZ[_2_] Excel Programming 1 October 16th 03 09:26 PM


All times are GMT +1. The time now is 11:34 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"