CFDATE

CFDATE(Function_Num,Cell_Ref,Week_Start)
Func_Num
Required. 1☛Yesterday, 2☛Today, 3☛Tomorrow, 4☛Last Week, 5☛This Week, 6☛Next Week, 7☛Last Month, 8☛This Month, 9☛Next Month, 10☛Last Year, 11☛This Year, 12☛Next Year.
Cell_Ref
Required. Upper left most cell of conditional formatting range. Must be relative or mixed reference.
Week_Start
Required for Numbers 4,5,6. Number corresponding to start of week - see WEEKDAY.

CFDATE is used for Conditional Formatting and returns TRUE or FALSE given a function number (1-12) related to dates and a cell reference.

schardt679

Board Regular
Joined
Mar 27, 2021
Messages
58
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
CFDATE is used for Conditional Formatting and returns TRUE or FALSE given a function number (1-12) related to dates and a cell reference.

Excludes blanks but not 0's.
Functions are 1☛Yesterday, 2☛Today, 3☛Tomorrow, 4☛Last Week, 5☛This Week, 6☛Next Week, 7☛Last Month, 8☛This Month, 9☛Next Month, 10☛Last Year, 11☛This Year, 12☛Next Year
Week_Start uses same values as WEEKDAY's return_type (11-17). Sunday (17) is the default.

Excel Formula:
=LAMBDA(Func_Num,Cell_Ref,Week_Start,
       LET(Func, Func_Num,    Ref, Cell_Ref,    Week, Week_Start,
           T_Day, TODAY(),  Wk_Day, WEEKDAY(T_Day, IF(Week=0, 17, Week)),
           ThisMon, MONTH(T_Day),    ThisYr, YEAR(T_Day),
           RefMon, MONTH(Ref),    RefYr, YEAR(Ref),
           ThisWkStart, T_Day-Wk_Day+1,    ThisWkEnd, T_Day-Wk_Day+7,
           YES, Ref=T_Day-1,   TOD, Ref=T_Day,    TOM, Ref=T_Day+1,
           WK_L, AND(Ref>=ThisWkStart-7, Ref<=ThisWkEnd-7),
           WK, AND(Ref>=ThisWkStart, Ref<=ThisWkEnd),
           WK_N, AND(Ref>=ThisWkStart+7, Ref<=ThisWkEnd+7),
           MON_L, RefMon=ThisMon-1,
           MON, RefMon=ThisMon,
           MON_N, RefMon=ThisMon+1,
           YR_L, RefYr=ThisYr-1,
           YR, RefYr=ThisYr,
           YR_N, RefYr=ThisYr+1,
           F1_6, SWITCH(Func,  1, YES,  2, TOD,  3, TOM,  4, WK_L,  5, WK,  6, WK_N,  0),
           F7_12, SWITCH(Func,  7, MON_L,  8, MON,  9, MON_N,  10, YR_L,  11, YR,  12, YR_N,  0),
           Result, IF(--(F1_6)=1, F1_6, F7_12),
           Return, IF(Ref="", 0, Result),
           Return
       )
  )

LAMBDA Examples.xlsx
ABCDEFGH
1CFDATE
2
3Sample DataConditional Formatting Colors
4YeserdayTodayTomorrowFunc_NumFunction
506/28/202106/28/202106/28/20211Yesterday (YES)
606/29/202106/29/202106/29/20212Today (TOD)
706/30/202106/30/202106/30/20213Tomorrow (TOM)
807/01/202107/01/202107/01/2021
907/02/202107/02/202107/02/2021
1007/03/202107/03/202107/03/2021
1107/04/202107/04/202107/04/2021
12
13
14Sample DataConditional Formatting Colors
15Last WeekThis WeekNext WeekFunc_NumFunction
1606/16/202106/16/202106/16/20214Last Week (WK_L)
1706/23/202106/23/202106/23/20215This Week (WK)
1807/01/202107/01/202107/01/20216Next Week (WK_N)
1907/02/202107/02/202107/02/2021
2007/07/202107/07/202107/07/2021
2107/14/202107/14/202107/14/2021
2207/21/202107/21/202107/21/2021
23
24
25Sample DataConditional Formatting Colors
26Last MonthThis MonthNext MonthFunc_NumFunction
2705/03/202105/03/202105/03/20217Last Month (MON_L)
2805/08/202105/08/202105/08/20218This Month (MON)
2906/20/202106/20/202106/20/20219Next Month (MON_N)
3006/11/202106/11/202106/11/2021
3106/30/202106/30/202106/30/2021
3207/04/202107/04/202107/04/2021
3307/25/202107/25/202107/25/2021
34
35
36Sample DataConditional Formatting Colors
37Last YearThis YearNext YearFunc_NumFunction
3802/21/202002/21/202002/21/202010Last Year(YR_L)
3907/03/202007/03/202007/03/202011This Year (YR)
4001/06/202101/06/202101/06/202112Next Year (YR_N)
4108/03/202108/03/202108/03/2021
4203/23/202203/23/202203/23/2022
4305/30/202205/30/202205/30/2022
4407/21/202207/21/202207/21/2022
45
CFDATE
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B5:B11Expression=CFDATE(1, B5,)textNO
C5:C11Expression=CFDATE(2, C5,)textNO
D5:D11Expression=CFDATE(3, D5,)textNO
B16:B22Expression=CFDATE(4, B16, 17)textNO
C16:C22Expression=CFDATE(5, C16, 17)textNO
D16:D22Expression=CFDATE(6, D16, 17)textNO
B27:B33Expression=CFDATE(7, B27,)textNO
C27:C33Expression=CFDATE(8, C27,)textNO
D27:D33Expression=CFDATE(9, D27,)textNO
B38:B44Expression=CFDATE(10, B38,)textNO
C38:C44Expression=CFDATE(11, C38,)textNO
D38:D44Expression=CFDATE(12, D38,)textNO
 
Upvote 0

Forum statistics

Threads
1,224,836
Messages
6,181,251
Members
453,027
Latest member
Lost_in_spreadsheets

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top