DATEDIF with INDIRECT function?

DrDebit

Board Regular
Joined
May 20, 2013
Messages
123
Office Version
  1. 365
Platform
  1. Windows
Is it possible to use the INDIRECT function as the third argument with the DATEDIF function?
TodayBirthdayYMDMDYMYD
11/5/2021​
10/5/1979​
42​
#REF!​
#REF!​
#REF!​
#REF!​
#REF!​
The function that I am using in C2 is =DATEDIF($B$2,$A$2,"Y") ... perfect...
...but in D2 is =DATEDIF($B$2,$A$2,INDIRECT(D1))...I get a #REF! error
Why doesn't it work? Is there a way to make it work?
Thank you.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
You don't need INDIRECT to do what you want.

21 11 06.xlsm
ABCDEFGH
1TodayBirthdayYMDMDYMYD
25/11/20215/10/197942505153720131
DATEDIF
Cell Formulas
RangeFormula
C2:H2C2=DATEDIF($B$2,$A$2,C$1)
 
Upvote 0
Work off day count.xlsx
ABCDEFGH
1Supporting Name ListYMDMDYMYD
2Indirect ValueYMDMDYMYD
3
4TodayBirthdayYMDMDYMYD
506-Nov-202110-May-19794250915521275180
Sheet2
Cell Formulas
RangeFormula
C5C5=DATEDIF($B$5,$A$5,INDIRECT(Y))
D5D5=DATEDIF($B$5,$A$5,INDIRECT(M))
E5E5=DATEDIF($B$5,$A$5,INDIRECT(D))
F5F5=DATEDIF($B$5,$A$5,INDIRECT(MD))
G5G5=DATEDIF($B$5,$A$5,INDIRECT(YM))
H5H5=DATEDIF($B$5,$A$5,INDIRECT(YD))
Named Ranges
NameRefers ToCells
D=Sheet2!$E$2E5
M=Sheet2!$D$2D5
MD=Sheet2!$F$2F5
Y=Sheet2!$C$2C5
YD=Sheet2!$H$2H5
YM=Sheet2!$G$2G5
 
Upvote 0
@FMHasan @DrDebit
Whilst that works, creating the named ranges is not needed as demonstrated above.
Even if you do create the named ranges as you have, there is still no need o to use INDIRECT as shown below. See also the final bullet point below.

21 11 06.xlsm
ABCDEFGH
1Supporting Name ListYMDMDYMYD
2Indirect ValueYMDMDYMYD
3
4TodayBirthdayYMDMDYMYD
506-Nov-2110-May-794250915521275180
DATEDIF (2)
Cell Formulas
RangeFormula
C5C5=DATEDIF($B$5,$A$5,Y)
D5D5=DATEDIF($B$5,$A$5,M)
E5E5=DATEDIF($B$5,$A$5,D)
F5F5=DATEDIF($B$5,$A$5,MD)
G5G5=DATEDIF($B$5,$A$5,YM)
H5H5=DATEDIF($B$5,$A$5,YD)
Named Ranges
NameRefers ToCells
D='DATEDIF (2)'!$E$2E5
M='DATEDIF (2)'!$D$2D5
MD='DATEDIF (2)'!$F$2F5
Y='DATEDIF (2)'!$C$2C5
YD='DATEDIF (2)'!$H$2H5
YM='DATEDIF (2)'!$G$2G5


Further,
  • using the named ranges requires every formula to be entered separately whereas the formula I suggested in post #2 can be just copied across.
  • INDIRECT is a volatile function so really should be avoided wherever there is a viable alternative, and there certainly is here.
 
Upvote 0
Thank you so much. Silly me.

David


You don't need INDIRECT to do what you want.

21 11 06.xlsm
ABCDEFGH
1TodayBirthdayYMDMDYMYD
25/11/20215/10/197942505153720131
DATEDIF
Cell Formulas
RangeFormula
C2:H2C2=DATEDIF($B$2,$A$2,C$1)
[/RANGE
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,379
Members
452,907
Latest member
Roland Deschain

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