Age formula not calculating

%3CLINGO-SUB%20id%3D%22lingo-sub-1622491%22%20slang%3D%22en-US%22%3EAge%20formula%20not%20calculating%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622491%22%20slang%3D%22en-US%22%3E%3CP%3EGood%20day%2C%20I%20am%20a%20beginner%20Excel%20user%20and%20am%20trying%20to%20calculate%20age%20between%202%20different%20dates%20where%20%3CSTRONG%3EB2%3C%2FSTRONG%3E%20contains%20the%20date%20of%20diagnosis%20of%20a%20disease%20and%20%3CSTRONG%3EE2%3C%2FSTRONG%3E%20contains%20the%20date%20of%20birth.%20The%20column%20with%20my%20formula%20is%20formatted%20to%20%22Number%22%20and%20Calculation%20is%20set%20to%20Automatic.%20I%20have%20also%20done%20the%20text%20to%20Column%20thing.%20My%20date%20columns%20are%20set%20to%20the%20same%20date%20format.%3C%2FP%3E%3CP%3EI%20type%20in%20the%20following%20formula%3A%20%3CSTRONG%3E%3Ddatediff(B2%2CE2%2C%22M%22)%3C%2FSTRONG%3E%2C%20but%20I%20receive%20an%20error%20message%20that%20there%20is%20a%20problem%20with%20the%20formula%20(the%20part%20between%20brackets%20is%20then%20highlighted).%20Also%2C%20when%20I%20type%20%22B2%22%20that%20column%20is%20highlighted%20blue%2C%20but%20when%20I%20type%20%22E2%22%2C%20that%20column%20is%20NOT%20highlighted%20red%20as%20I%20expected%20it%20to.%3C%2FP%3E%3CP%3EHow%20can%20I%20fix%20this%20error%20and%20calculate%20the%20age%3F%20Would%20really%20appreciate%20your%20help!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1622491%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1622565%22%20slang%3D%22en-US%22%3ERe%3A%20Age%20formula%20not%20calculating%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622565%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F776678%22%20target%3D%22_blank%22%3E%40Anel0510%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDouble%20%22f%22%20is%20for%20the%20function%20in%20VBA%2C%20here%20is%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DDATEDIF(E3%2CG3%2C%22Y%22)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eor%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DYEARFRAC(G2%2CE2%2C1)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Edepend%20on%20what%20exactly%20you'd%20like%20to%20calculate.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1622621%22%20slang%3D%22en-US%22%3ERe%3A%20Age%20formula%20not%20calculating%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622621%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Sergei%2C%20thanks%20for%20your%20reply!%20I%20have%20tried%20using%20both%20your%20suggested%20formulas%20(copy%20and%20pasted%20them)%2C%20but%20I%20still%20get%20a%20message%20that%20there%20is%20an%20error%20(see%20attached%20file).%3C%2FP%3E%3CP%3EAny%20other%20suggestions%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1622686%22%20slang%3D%22en-US%22%3ERe%3A%20Age%20formula%20not%20calculating%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622686%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F776678%22%20target%3D%22_blank%22%3E%40Anel0510%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnother%20formula%20you%20can%20use%20is%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3D(G2-E2)%2F365.25%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSTRONG%3E%20(the%20.25%20because%20that%20is%20the%20more%20precise%20number%20of%20days%20in%20a%20year%2C%20accounting%20for%20leap%20years)%3CSTRONG%3E%3CBR%20%2F%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EThat%20formula%20has%20been%20put%20into%20the%20attached%20copy%20of%20your%20spreadsheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESeparate%20issue%3A%20the%20copy%20you%20posted%20contained%20information%20that%20should%20have%20been%20deleted%20before%20posting...names%20of%20patients.%20It's%20important%20that%20such%20private%20info%20NOT%20be%20posted.%20You%20can%20remove%20the%20sheet%20yourself%2C%20but%20if%20you%20don't%20get%20to%20it%20in%20time%2C%20I've%20alerted%20the%20board%20moderators%20to%20take%20it%20down.%20In%20the%20copy%20I'm%20attaching%2C%20the%20sheet%20with%20those%20names%20has%20been%20removed.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1622711%22%20slang%3D%22en-US%22%3ERe%3A%20Age%20formula%20not%20calculating%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622711%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F776678%22%20target%3D%22_blank%22%3E%40Anel0510%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20say%20that%20you're%20a%20beginner%20at%20Excel%2C%20so%20I'll%20be%20presumptuous%20and%20note%20that%20there%20are%20other%20things%20you%20could%20do%20that%20might%20make%20your%20overall%20spreadsheet%20easier%20to%20maintain.%20Certainly%20there%20are%20%22tricks%22%20you%20could%20learn%20that%20will%20be%20beneficial%20in%20the%20future.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20you%20have%20today's%20date%20appearing%20in%20every%20row%2C%20and%20then%20use%20that%20redundant%20data%20in%20the%20calculation%20of%20the%20ages%20of%20the%20patient%20referred%20to%20in%20that%20row.%20More%20efficient%20would%20be%20to%20have%20a%20separate%20cell%20off%20to%20the%20side%2Csay%20in%20cell%20M1%20and%20have%20that%20cell%20contain%20today's%20date.%20%3DTODAY()%3C%2FP%3E%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E(that%20%22off%20to%20the%20side%22%20could%20also%20be%20elaborated%20on%20in%20a%20later%20lesson.)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20the%20age%20calculation%20in%20your%20cell%20C2%2C%20now%20reading%20%3DDATEDIF(E2%2CD2%2C%22M%22)%20would%20become%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DDATEDIF(%24M%241%2CD2%2C%22M%22)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EThose%20dollar%20signs%20make%20the%20reference%20a%20%22%3CEM%3Eabsolute%20reference%3C%2FEM%3E%22%20instead%20of%20the%20%22%3CEM%3Erelative%20reference%3C%2FEM%3E%22%20of%20E2.%20Then%2C%20when%20you%20copy%20the%20formula%20down%20to%20all%20the%20lower%20rows%2C%20it%20stays%20%24M%241%2C%20while%20the%20D2%20becomes%20D3%2C%20D4%2C.....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat's%20the%20way%20to%20handle%20variables%20that%20are%2C%20in%20fact%2C%20semi-constant%20and%20that%20are%20referred%20to%20in%20multiple%20places%20in%20a%20spreadsheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'd%20also%20recommend%20looking%20into%20%3CSTRONG%3EData%20Validation%3C%2FSTRONG%3E.%20It%20occurs%20to%20me%20that%20you%20may%20have%20downloaded%20the%20actual%20diagnoses%20(and%20possible%20all%20of%20the%20patient%20data)...but%20if%20you%20find%20yourself%20adjusting%20diagnoses%2C%20Data%20Validation%20could%20save%20typing%20the%20words%20and%20insure%20consistency.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1622735%22%20slang%3D%22en-US%22%3ERe%3A%20Age%20formula%20not%20calculating%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622735%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F776678%22%20target%3D%22_blank%22%3E%40Anel0510%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPerhaps%20in%20your%20locale%20you%20shall%20use%20semicolons%2C%20not%20commas.%20Please%20check%20how%20it%20is%20in%20other%20formulas.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DDATEDIF(E3%3BG3%3B%22Y%22)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1622730%22%20slang%3D%22en-US%22%3ERe%3A%20Age%20formula%20not%20calculating%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622730%22%20slang%3D%22en-US%22%3E%3CP%3EDear%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F425987%22%20target%3D%22_blank%22%3E%40mathetes%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20much%20for%20all%20the%20valuable%20advice%3B%20I%20truly%20appreciate%20it!%20Thank%20you%20also%20for%20calculating%20the%20ages%20for%20me%3A)%3C%2FP%3E%3CP%3EI%20think%20I%20overlooked%20the%202nd%20sheet%20with%20personal%20information%20when%20I%20posted%3B%20will%20double-check%20in%20future%20and%20remove%20my%20attachment%20ASAP.%3C%2FP%3E%3CP%3EHave%20a%20lovely%20day%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Good day, I am a beginner Excel user and am trying to calculate age between 2 different dates where B2 contains the date of diagnosis of a disease and E2 contains the date of birth. The column with my formula is formatted to "Number" and Calculation is set to Automatic. I have also done the text to Column thing. My date columns are set to the same date format.

I type in the following formula: =datediff(B2,E2,"M"), but I receive an error message that there is a problem with the formula (the part between brackets is then highlighted). Also, when I type "B2" that column is highlighted blue, but when I type "E2", that column is NOT highlighted red as I expected it to.

How can I fix this error and calculate the age? Would really appreciate your help!

 

8 Replies
Highlighted

@Anel0510 

Double "f" is for the function in VBA, here is 

=DATEDIF(E3,G3,"Y")

or

=YEARFRAC(G2,E2,1)

depend on what exactly you'd like to calculate.

Highlighted

Hi Sergei, thanks for your reply! I have tried using both your suggested formulas (copy and pasted them), but I still get a message that there is an error (see attached file).

Any other suggestions?

Highlighted

@Anel0510 

 

Another formula you can use is

=(G2-E2)/365.25    (the .25 because that is the more precise number of days in a year, accounting for leap years)

That formula has been put into the attached copy of your spreadsheet.

 

Separate issue: the copy you posted contained information that should have been deleted before posting...names of patients. It's important that such private info NOT be posted. You can remove the sheet yourself, but if you don't get to it in time, I've alerted the board moderators to take it down. In the copy I'm attaching, the sheet with those names has been removed.

Highlighted

@Anel0510 

 

You say that you're a beginner at Excel, so I'll be presumptuous and note that there are other things you could do that might make your overall spreadsheet easier to maintain. Certainly there are "tricks" you could learn that will be beneficial in the future.

 

For example, you have today's date appearing in every row, and then use that redundant data in the calculation of the ages of the patient referred to in that row. More efficient would be to have a separate cell off to the side,say in cell M1 and have that cell contain today's date. =TODAY()

(that "off to the side" could also be elaborated on in a later lesson.)

 

Then the age calculation in your cell C2, now reading =DATEDIF(E2,D2,"M") would become

=DATEDIF($M$1,D2,"M")

Those dollar signs make the reference a "absolute reference" instead of the "relative reference" of E2. Then, when you copy the formula down to all the lower rows, it stays $M$1, while the D2 becomes D3, D4,.....

 

That's the way to handle variables that are, in fact, semi-constant and that are referred to in multiple places in a spreadsheet.

 

I'd also recommend looking into Data Validation. It occurs to me that you may have downloaded the actual diagnoses (and possible all of the patient data)...but if you find yourself adjusting diagnoses, Data Validation could save typing the words and insure consistency.

Highlighted

Dear @mathetes ,

 

Thank you so much for all the valuable advice; I truly appreciate it! Thank you also for calculating the ages for me:)

I think I overlooked the 2nd sheet with personal information when I posted; will double-check in future and remove my attachment ASAP.

Have a lovely day

 

Highlighted

@Anel0510 

Perhaps in your locale you shall use semicolons, not commas. Please check how it is in other formulas.

=DATEDIF(E3;G3;"Y")

 

Highlighted

Thank you @Sergei Baklan, that seems to work! 

Highlighted

@Anel0510 , you are welcome