SOLVED

Auto formatting

%3CLINGO-SUB%20id%3D%22lingo-sub-2593297%22%20slang%3D%22en-US%22%3EAuto%20formatting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2593297%22%20slang%3D%22en-US%22%3EI%20have%20a%20spreadsheet%20with%20DOB.%3CBR%20%2F%3EI%20was%20wondering%20if%20there%20was%20a%20way%20that%20on%20opening%20the%20spreadsheet%20it%20would%20highlight%20the%20DOB%20of%20those%20turning%2012%2C%2018%20or%2024%20years%20of%20age%20within%20the%20next%202%20months.%3CBR%20%2F%3EAny%20formula%20suggestions%20would%20be%20appreciated.%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2593297%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2593385%22%20slang%3D%22en-US%22%3ERe%3A%20Auto%20formatting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2593385%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1114088%22%20target%3D%22_blank%22%3E%40PPatel19%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet's%20say%20the%20dates%20of%20birth%20are%20in%20D2%3AD100.%3C%2FP%3E%0A%3CP%3ESelect%20this%20range.%20D2%20should%20be%20the%20active%20cell%20in%20the%20selection.%3C%2FP%3E%0A%3CP%3EOn%20the%20Home%20tab%20of%20the%20ribbon%2C%20select%20Conditional%20Formatting%20%26gt%3B%20New%20Rule...%3C%2FP%3E%0A%3CP%3ESelect%20'Use%20a%20formula%20to%20determine%20which%20cells%20to%20format'.%3C%2FP%3E%0A%3CP%3EEnter%20the%20formula%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DOR(AND(%24D2%26gt%3BEOMONTH(TODAY()%2C-288)%2C%24D2%26lt%3B%3DEOMONTH(TODAY()%2C-286))%2CAND(%24D2%26gt%3BEOMONTH(TODAY()%2C-216)%2C%24D2%26lt%3B%3DEOMONTH(TODAY()%2C-214))%2CAND(%24D2%26gt%3BEOMONTH(TODAY()%2C-144)%2C%24D2%26lt%3B%3DEOMONTH(TODAY()%2C-142)))%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EClick%20Format...%3C%2FP%3E%0A%3CP%3EActivate%20the%20Fill%20tab.%3C%2FP%3E%0A%3CP%3ESelect%20a%20color.%3C%2FP%3E%0A%3CP%3EClick%20OK%2C%20then%20click%20OK%20again.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2593697%22%20slang%3D%22en-US%22%3ERe%3A%20Auto%20formatting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2593697%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%3CBR%20%2F%3EThank%20you%20very%20much.%20That%20worked%20perfectly%3CBR%20%2F%3EMy%20understanding%20of%20formulas%20is%20fairly%20basic.%20If%20possible%20it%20would%20be%20great%20if%20you%20could%20provide%20a%20breakdown%20explanation%20of%20the%20formula.%3CBR%20%2F%3ESo%20that%20I%20could%20shorten%20or%20widen%20the%20month%20range%20(e.g.%201%20month%20or%203%20months).%20Or%20even%20split%20the%20formula%20so%20I%20could%20have%20a%20different%20colour%20code%20for%20the%20different%20ages.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
Occasional Contributor
I have a spreadsheet with DOB.
I was wondering if there was a way that on opening the spreadsheet it would highlight the DOB of those turning 12, 18 or 24 years of age within the next 2 months.
Any guidance or formula suggestions would be appreciated.
11 Replies
best response confirmed by allyreckerman (Microsoft)
Solution

@PPatel19 

Let's say the dates of birth are in D2:D100.

Select this range. D2 should be the active cell in the selection.

On the Home tab of the ribbon, select Conditional Formatting > New Rule...

Select 'Use a formula to determine which cells to format'.

Enter the formula

 

=OR(AND($D2>EOMONTH(TODAY(),-288),$D2<=EOMONTH(TODAY(),-286)),AND($D2>EOMONTH(TODAY(),-216),$D2<=EOMONTH(TODAY(),-214)),AND($D2>EOMONTH(TODAY(),-144),$D2<=EOMONTH(TODAY(),-142)))

 

Click Format...

Activate the Fill tab.

Select a color.

Click OK, then click OK again.

@Hans Vogelaar
Thank you very much. That worked perfectly
My understanding of formulas is fairly basic. If possible it would be great if you could provide a breakdown explanation of the formula.
So that I could shorten or widen the month range (e.g. 1 month or 3 months). Or even split the formula so I could have a different colour code for the different ages.

@PPatel19 

I should have used EDATE instead of EOMONTH, sorry.

If you want different colors, create 3 rules, with formulas

 

AND($D2>EDATE(TODAY(),-24*12),$D2<=EDATE(TODAY(),-24*12+2))

 

AND($D2>EDATE(TODAY(),-18*12),$D2<=EDATE(TODAY(),-18*12+2))

 

AND($D2>EDATE(TODAY(),-12*12),$D2<=EDATE(TODAY(),-12*12+2))

 

EDATE(somedate, n) returns the date n months after somedate. If n is negative, it returns a date before somedate.

 

24 years is 24*12 months, 18 years is 18*12 months, and 12 years is 12*12 months.

So $D2>EDATE(TODAY(),-24*12) requires that the date of birth is later than 24 years ago.

And $D2<=EDATE(TODAY(),-12*12+2) requires that the date of birth is not later than 2 months after 24 years ago. If you want a narrower or wider range, change the number 2 accordingly. For example: for 3 months, you'd use

 

AND($D2>EDATE(TODAY(),-24*12),$D2<=EDATE(TODAY(),-24*12+3))

 

etc.

@Hans Vogelaar
Thanks again. Explanation is also extremely useful.

@Hans Vogelaar - Couple of follow ups

1. You explained 'EDATE(somedaten) returns the date n months after somedate. If n is negative, it returns a date before somedate.' - in terms of the formula you have provided would you just change the 'TODAY' to 'SOMEDATE'?

AND($D2>EDATE(SOMEDATE(),-24*12),$D2<=EDATE(TODAY(),-24*12+2))

2. Using the function 'EDATE' highlights the required age groups in this month July and August. Whereas the formula you provided with the function 'EOMONTH' highlighted August and September. I tried changing your formula as below so it would highlight as the latter, but that doesn't appear to work:

AND($D2>EOMONTH(TODAY(),-24*12),$D2<=EOMONTH(TODAY(),-24*12+2))

 

Apologies if I'm confusing matters. 

 

To explain fully what I am trying to do. At the start of any given month I pull a report I then need to identify which individuals are turning 12, 18, 24 in the next month. So in August I would be looking at who would turn 12, 18, 24 in September. The option to widen that range is useful. 

 

 

@PPatel19 

SOMEDATE was only meant to explain the syntax of EDATE (and EOMONTH); it can be replaced with any date.

In your particular situation, we use TODAY() because we want to refer to the current date.

 

If you want to highlight dates in the next calendar month, we'll use EOMONTH:

 

=AND($D2>EOMONTH(TODAY(),-24*12),$D2<=EOMONTH(TODAY(),-24*12+1))

=AND($D2>EOMONTH(TODAY(),-18*12),$D2<=EOMONTH(TODAY(),-18*12+1))

=AND($D2>EOMONTH(TODAY(),-12*12),$D2<=EOMONTH(TODAY(),-12*12+1))

 

For example EOMONTH(TODAY(),-24*12) is the last day of the month 24 years before today. So currently, that is 31-July-1997.

And EOMONTH(TODAY(),-24*12+1) is the last day of the month after that. So currently, that is 31-August-1997

=AND($D2>EOMONTH(TODAY(),-24*12),$D2<=EOMONTH(TODAY(),-24*12+1)) says: the date of birth is after 31-July-1997 and on or before 31-August-1997.

 

Next month, when it is August 2021, EOMONTH(TODAY(),-24*12) will be 31-August-1997 and EOMONTH(TODAY(),-24*12+1) will be 30-September-1997.

 

If you would like to highlight those that will be 24 in the next 2 calendar months, use

 

=AND($D2>EOMONTH(TODAY(),-24*12),$D2<=EOMONTH(TODAY(),-24*12+2))

 

etc.

@Hans Vogelaar Hi again, another follow up. I’m working with an additional spreadsheet that has 5 columns with DOB.
Can the formula be amended so it can be applied to the different columns in one instant.
Thanks P

@PPatel19 

Remove the $ signs from the expression, i.e. D2 instead of $D2.

Make sure that the formula refers to the top left cell of the selection.

@Hans Vogelaar So
=AND(AD2,AK2,AR2,AY2,BH2>EOMONTH(TODAY(),-24*12), AD2,AK2,AR2,AY2,BH2<=EOMONTH(TODAY(),-24*12+1))

@PPatel19 

No, simply

 

=AND(AD2>EOMONTH(TODAY(),-24*12), AD2<=EOMONTH(TODAY(),-24*12+1))

Ok thank you