Fill cells if between dates

ashley1984

New Member
Joined
Mar 31, 2018
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to fill cells if they are between a specific date as entered by a user. E.g.

If I had the dates as entered (dd/mm/yyyy) between 5th Jan & December 2021, then all the cells under the corresponding month would fill with my chosen colour.

If I had to change the end date to 01/06/2021 then the cells between and June would be filled

thanks

Start DateEnd DateJanFebMarchAprilMayJuneJul Aug etc
05/01/202131/12/2021
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Are the month names just text or dates formatted to show the month?
Also what version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Months are just text but can change to date format if needed.

I'm using 365 on Windows. Updated my user profile to reflect this
 
Upvote 0
Conditional formatting formula:
MrExcelPlayground.xlsm
ABCDEFGHIJKLMN
1StartEndJan-21Feb-21Mar-21Apr-21May-21Jun-21Jul-21Aug-21Sep-21Oct-21Nov-21Dec-21
21/5/202112/31/2021
36/5/20216/25/2021
42/15/20219/30/2021
51/5/20212/1/2021
62/14/20219/29/2021
Sheet32
Cell Formulas
RangeFormula
D1:N1D1=EOMONTH(C1,1)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:N6Expression=SUM(--(MONTH(C$1)=ROW(INDIRECT(MONTH($A2)&":"&MONTH($B2)))))=1textNO
 
Upvote 0
Thanks for that, if you convert them to dates you can use
+Fluff 1.xlsm
ABCDEFGHIJKLMN
1Start DateEnd DateJanFebMarAprMayJunJulAugSepOctNovDec
205/01/202131/12/2021
305/04/202107/10/2021
401/06/202101/08/2021
5
Master
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:N4Expression=AND($A2<>"",$B2<>"",MONTH($A2)<=MONTH(C$1),MONTH($B2)>=MONTH(C$1))textNO
 
Upvote 0
Conditional formatting formula:
MrExcelPlayground.xlsm
ABCDEFGHIJKLMN
1StartEndJan-21Feb-21Mar-21Apr-21May-21Jun-21Jul-21Aug-21Sep-21Oct-21Nov-21Dec-21
21/5/202112/31/2021
36/5/20216/25/2021
42/15/20219/30/2021
51/5/20212/1/2021
62/14/20219/29/2021
Sheet32
Cell Formulas
RangeFormula
D1:N1D1=EOMONTH(C1,1)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:N6Expression=SUM(--(MONTH(C$1)=ROW(INDIRECT(MONTH($A2)&":"&MONTH($B2)))))=1textNO
Thanks, this works to some extent. Few questions, your dates appear to be American, how do I do this in UK (DD/MM/YYYY). I managed to get it to work but how do I get this to fill into 2022. For example, if the start date is 12th September 2021 but the end date is only the 1st March 2022 how would I do this? I've set up the =EOMMONTH formula to go to the end of Dec 2023, starting Jan 2021 and applied the conditional formating to the whole date range
 
Upvote 0
Thanks for that, if you convert them to dates you can use
+Fluff 1.xlsm
ABCDEFGHIJKLMN
1Start DateEnd DateJanFebMarAprMayJunJulAugSepOctNovDec
205/01/202131/12/2021
305/04/202107/10/2021
401/06/202101/08/2021
5
Master
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:N4Expression=AND($A2<>"",$B2<>"",MONTH($A2)<=MONTH(C$1),MONTH($B2)>=MONTH(C$1))textNO
Thanks, this also works to some extent. I should have been clearer in my original post that my date range extended to December 2023, so I might have dates over two years e.g. 01/09/21 to 03/06/22. Your suggestion works to some extent but if I enter 01/01/21 to 09/09/21 the cells highlight the correct months but then the cells for 2022 & 2023 are filled in as well?
 
Upvote 0
Thanks, this works to some extent. Few questions, your dates appear to be American, how do I do this in UK (DD/MM/YYYY). I managed to get it to work but how do I get this to fill into 2022. For example, if the start date is 12th September 2021 but the end date is only the 1st March 2022 how would I do this? I've set up the =EOMMONTH formula to go to the end of Dec 2023, starting Jan 2021 and applied the conditional formating to the whole date range

Date format doesn't matter. THe month function will work. But fluff's is a better function. IF you want to get years involved it gets a bit more complicated.

Everywhere you have "Month(XX), replace it with "100*year(xx)+month(xx)".
 
Upvote 0
How about
+Fluff 1.xlsm
ABCDEFGHIJKLMNOPQ
1Start DateEnd DateJanFebMarAprMayJunJulAugSepOctNovDecJanFebMar
205/01/202131/12/2021
305/04/202107/10/2021
401/08/202107/03/2022
5
Master
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:Q5Expression=AND($A2<>"",$B2<>"",EOMONTH($A2,-1)+1<=C$1,EOMONTH($B2,0)>=C$1)textNO
 
Upvote 0
Solution

Forum statistics

Threads
1,215,786
Messages
6,126,893
Members
449,347
Latest member
Macro_learner

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