Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2024, 02:24 AM
ArviLaanemets ArviLaanemets is offline Date Formula Windows 8 Date Formula Office 2016
Expert
 
Join Date: May 2017
Posts: 949
ArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant future
Default

Or in A3 use (assumed the worksheet is never used at weekends, and you have to cope with state holidays otherwise)
Code:
=TODAY() - IIF(WEEKDAY(TODAY(),2)=1,3,1)
In case you need to take holidays also into account, you need a hidden calendar table with state holidays marked, and with a calculated column which returns the number of days to previous workday in case of holiday or weekend (p.e. for my country, this may be up to 5 days if I remember correctly), and 0 in case of workday. The formula in A3 will calculate the previous workday based on this hidden table.
Reply With Quote
  #2  
Old 11-22-2024, 06:42 AM
Karen615 Karen615 is offline Date Formula Windows 11 Date Formula Office 2021
Competent Performer
Date Formula
 
Join Date: Jun 2011
Location: Chicago
Posts: 145
Karen615 is on a distinguished road
Default

Quote:
Originally Posted by ArviLaanemets View Post
Or in A3 use (assumed the worksheet is never used at weekends, and you have to cope with state holidays otherwise)
Code:
=TODAY() - IIF(WEEKDAY(TODAY(),2)=1,3,1)
In case you need to take holidays also into account, you need a hidden calendar table with state holidays marked, and with a calculated column which returns the number of days to previous workday in case of holiday or weekend (p.e. for my country, this may be up to 5 days if I remember correctly), and 0 in case of workday. The formula in A3 will calculate the previous workday based on this hidden table.
Thank you so much for your help. If you have a chance, would you please explain this formula in layman's terms?

Also, I do need to deal with holidays. I'm not sure how to set up that hidden calendar.

Your help is greatly appreciated.
Thank you,
Karen
Reply With Quote
  #3  
Old 11-22-2024, 08:29 AM
ArviLaanemets ArviLaanemets is offline Date Formula Windows 8 Date Formula Office 2016
Expert
 
Join Date: May 2017
Posts: 949
ArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant future
Default

Quote:
Originally Posted by Karen615 View Post
Thank you so much for your help. If you have a chance, would you please explain this formula in layman's terms?
The formula returns the date of previous Friday (TODAY-3), when the current date is Monday, i.e. the weekday number of current date is 1 (I used WEEKDAY() with 2nd argument 2 to get weekdays numbered from 1 = Monday to 7 = Sunday).
For other workdays (from Tuesday to Friday, with weekday numbers from 2 to 5), the formula returns the date of previous workday (TODAY -1).
As I declared in my precvious post, the formula in not meant to use at weekends.

In case you want this formula to work when the workbook is opened at weekends (but ignoring holidays) too, you have to use instead
Code:
=TODAY() - CHOOSE(WEEKDAY(TODAY(),2),3,1,1,1,1,1,2)
The CHOOSE() returns from values at 2nd to last parameters, the one with order number equal to value of 1st parameter

Quote:
Also, I do need to deal with holidays. I'm not sure how to set up that hidden calendar.
On separate sheet, create a table with header for column A (e.g. in cell A1) something like "Date". Into cell A2 enter the start date (e.g. January 1st of current year), into cell A2, enter the next date (e.g. January 2nd of current year), select both dates, and drag down (from right lower edge) to fill the column with as much dates you think you will need;
Add another column (e.g. column B with header "Weekday"), and fill it with weekday numbers using WEEKDAY() formula;
Add another column (e.g. column C with header "Holiday"), and fill it with number 1 for every holiday in daterange of your table. When the date isn't a holiday, leave it empty, or enter 0;
Add another column (e.g. column D with header "PreviousWD"). Based on info in columns B:C, fill this column with 0 when the date is workday and it is not a holiday. Otherwise enter, how many days back was last workday (1, or 2, or ... days). It is possible to create a formula for this column, but I'm afraid this will be too complex for you, and I don't have access to Excel currently, and even having it, the creating such formula will take hours for me too.

Now either define this calendar table as Table with name like tCalendar, or select the whole datarange of created table, and define it as Name like nCalendar (I'll continue with defined Name below).

On your original sheet, into cell A3 enter the formula like
Code:
=(TODAY()-1) - VLOOKUP((TODAY()-1),nCalendar,4,0)
The 3rd parameter of VLOOKUP() in formula indicates the 4th column of range nCalendar - i.e. the VLOOKUP() returns the matching number in column PreviousWD.

After checking the formula for previous workday working, you can hide the sheet with calendar table you created.

Last edited by ArviLaanemets; 11-22-2024 at 11:56 AM.
Reply With Quote
  #4  
Old 11-30-2024, 08:31 AM
Karen615 Karen615 is offline Date Formula Windows 11 Date Formula Office 2021
Competent Performer
Date Formula
 
Join Date: Jun 2011
Location: Chicago
Posts: 145
Karen615 is on a distinguished road
Default

Thank you so much for your detailed reply! Your explanation is incredibly helpful, and I truly appreciate the time and effort you put into this. People on this site are amazing!
Happy holidays!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Formula Issue matteu1 Mail Merge 1 07-23-2018 04:53 AM
Formula for looking at 1 cell with a date and then comparing it to four date ranges LearningMom Excel 3 10-27-2017 12:44 PM
Date Formula Formula to return a date caz46 Excel 3 04-15-2015 08:59 AM
Date Formula Need a date formula MPAVLAS Excel 3 08-12-2010 10:04 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft