# Change Cell Contents if Cell Date is in Previous Month / 4 Months

#### Mazzic

##### New Member
Good morning!

I have a layout that looks like this:

For one criteria, I would like to:
Display QUAL if the date is in the current or previous month.
Display NC/QUAL if the date is before the previous month.
Display UNQUAL if the date is blank.

For a different criteria, I would like to:
Display QUAL if the date is from May/June/July/Aug OR if the date is in Sept/Oct/Nov/Dec
Display NC/QUAL if the date is prior to May
Display UNQUAL if the date is blank.

#### Mazzic

##### New Member
One example for any of these would probably be enough for me to figure out the rest.

#### Fluff

##### MrExcel MVP, Moderator
For the first part what happens if the date is in the future?

#### Mazzic

##### New Member
The date entered should never be in the future based on the way the spreadsheet works, but in a formula case QUAL would be acceptable

#### Fluff

##### MrExcel MVP, Moderator
=IF(A2="","UN",IF(MONTH(TODAY())-MONTH(A2)>=2,"NC/",""))&"QUAL"

#### Mazzic

##### New Member
That works perfectly - truly impressed with your solution!

Looking to decipher your formula so I can re-arrange it based on the other parts of my spreadsheet, if the date range is blank, it returns UN. if the month of the date is either today's month or today's month minus two months, it returns NC/, and it always returns QUAL. Right?

#### Joe4

I would recommend using the DATEDIF function (https://exceljet.net/excel-functions/excel-datedif-function) instead of MONTH in case your dates aren't in the same year.
For example, let's say we were in January, and looking back at November or December dates. Substracting MONTHs will result in negative values.

#### Fluff

##### MrExcel MVP, Moderator
That works perfectly - truly impressed with your solution!

Looking to decipher your formula so I can re-arrange it based on the other parts of my spreadsheet, if the date range is blank, it returns UN. if the month of the date is either today's month or today's month minus two months, it returns NC/, and it always returns QUAL. Right?
You've understood it correctly.
Although as Joe4 has pointed out, I didn't factor in changing years.

1,081,931
Messages
5,362,195
Members
400,671
Latest member
Tommy00836

### This Week's Hot Topics

• populate from drop list with multiple tables
Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
• Find list of words from sheet2 in sheet1 before a comma and extract text vba
Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
• Dynamic Formula entry - VBA code sought
Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
• Complex Heat Map using conditional formatting
Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
• Conditional formatting
Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...