Conditional Formatting Not showing all lines | Gantt Style with Months

SimpleMan618

New Member
Joined
Sep 29, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Trying to solve conditional formatting that is not showing all the correct data. I believe the reason for this is that it starts prior to the first column month. Per the example, Baseball starts in Mar and through Sep(Current Month) and then ends in Oct. Because of that, it doesn't show any blue bars. The first column month is dynamic so the first month will always be the current month we are in. It took me a couple of days to figure out the condition I am currently using, and it's been a week trying to figure this out. Any help would be appreciated. Thank you

Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAA
2SportStartEndSepOctNovDecJanFebMarAprMayJunJulAugSepOctNovDecJanFebMarAprMayJunJulAug
3FootballSepJan
4BaseballMarOct
5SoccerFebNov
6BasketballOctJun
7HockeyOctJun
Sheet1
Cell Formulas
RangeFormula
D2D2=TEXT(TODAY(),"MMM")
E2:AA2E2=TEXT(EDATE(TODAY(),E1),"MMM")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D3:AA7Expression=AND(MATCH(D$2,$D$2:$AA$2,0)>=MATCH($B3,$D$2:$AA$2,0),MATCH(D$2,$D$2:$AA$2,0)<=MATCH($C3,$D$2:$AA$2,0))textNO
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Welcome! For the Conditional Formatting formula, try this:
Excel Formula:
=ISNUMBER(MATCH(MONTH(--(D$2&" 1, 2000")),MOD(SEQUENCE(,LET(d,MONTH(--($C3&" 1, 2000"))-MONTH(--($B3&" 1, 2000"))+1,IF(d<=0,12+d,d)),MONTH(--($B3&" 1, 2000")))-1,12)+1,0))
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAA
1
2SportStartEndSepOctNovDecJanFebMarAprMayJunJulAugSepOctNovDecJanFebMarAprMayJunJulAug
3FootballSepJan
4BaseballMarOct
5SoccerFebDec
6BasketballOctJun
7HockeyOctJun
Sheet1
Cell Formulas
RangeFormula
D2:AA2D2=TEXT(EDATE(TODAY(),SEQUENCE(,24,0)),"MMM")
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D3:AA7Expression=ISNUMBER(MATCH(MONTH(--(D$2&" 1, 2000")),MOD(SEQUENCE(,LET(d,MONTH(--($C3&" 1, 2000"))-MONTH(--($B3&" 1, 2000"))+1,IF(d<=0,12+d,d)),MONTH(--($B3&" 1, 2000")))-1,12)+1,0))textNO

Edit: Made a slight adjustment to formula to allow for year-long schedule...so Feb-Jan should work.
 
Last edited:
Upvote 0
Solution
Welcome! For the Conditional Formatting formula, try this:
Excel Formula:
=ISNUMBER(MATCH(MONTH(--(D$2&" 1, 2000")),MOD(SEQUENCE(,LET(d,MONTH(--($C3&" 1, 2000"))-MONTH(--($B3&" 1, 2000"))+1,IF(d<=0,12+d,d)),MONTH(--($B3&" 1, 2000")))-1,12)+1,0))
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAA
1
2SportStartEndSepOctNovDecJanFebMarAprMayJunJulAugSepOctNovDecJanFebMarAprMayJunJulAug
3FootballSepJan
4BaseballMarOct
5SoccerFebDec
6BasketballOctJun
7HockeyOctJun
Sheet1
Cell Formulas
RangeFormula
D2:AA2D2=TEXT(EDATE(TODAY(),SEQUENCE(,24,0)),"MMM")
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D3:AA7Expression=ISNUMBER(MATCH(MONTH(--(D$2&" 1, 2000")),MOD(SEQUENCE(,LET(d,MONTH(--($C3&" 1, 2000"))-MONTH(--($B3&" 1, 2000"))+1,IF(d<=0,12+d,d)),MONTH(--($B3&" 1, 2000")))-1,12)+1,0))textNO

Edit: Made a slight adjustment to formula to allow for year-long schedule...so Feb-Jan should work.
Thank KRice! This worked well. Hoping you can provide details on how the formula works so I can learn. Tried to walk through it on my own but was unable to put the pieces together. Thank you again
 
Upvote 0
Starting with the column headings, we use a formula similar to your original one, except instead of referring to what is probably a helper row in your original sheet, the SEQUENCE function is used to create an array of 24 sequential numbers, starting with 0. This array is fed to the EDATE function, which will then produce an array representing representing today's date and sequential months. Those dates are fed into the TEXT function to return just the three-letter month abbreviations, which spill across the row.
Excel Formula:
TEXT(EDATE(TODAY(),SEQUENCE(,24,0)),"MMM")

For the Conditional Formatting (CF) function, it is easier to break it down into several parts:
Excel Formula:
=ISNUMBER(MATCH(MONTH(--(D$2&" 1, 2000")),MOD(SEQUENCE(,LET(d,MONTH(--($C3&" 1, 2000"))-MONTH(--($B3&" 1, 2000"))+1,IF(d<=0,12+d,d)),MONTH(--($B3&" 1, 2000")))-1,12)+1,0))

Somehow, the three-letter month abbreviations need to the expressed in terms of their month numbers. This can be done many different ways. I used a method that constructs a date from the month abbreviation by concatenating the month with a day (1) and a year (2000). The concatenation is still a text representation of the date, e.g., "Sep 1, 2000", so to coerce Excel to convert this to a numeric date value, the double unary operator (--) is used...and then the MONTH function will accept that numeric date as an argument. The choice of day number and year are arbitrary, as the MONTH function will return only the month number for whichever date is passed to it. Within the CF formula, you will see these components:
Excel Formula:
MONTH(--($B3&" 1, 2000"))   StartMonthNumber of season
Excel Formula:
MONTH(--($C3&" 1, 2000"))   EndMonthNumber of season
Excel Formula:
MONTH(--(D$2&" 1, 2000"))   ColumnMonthNumber of the 2-year calendar
...each returning a month number of the cell referenced. For example, if $B3 is Sep and $C3 is Jan, we'll get 9 and 1, the first two formulas will return 9 and 1.

Within the CF formula, these components are used for various purposes. In the LET function, we define the sport season durations (d) in terms of the difference between EndMonthNumber and StartMonthNumber (note 1 is added to account for both start and end months, and not just the intervals):
Excel Formula:
d, MONTH(--($C3&" 1, 2000")) - MONTH(--($B3&" 1, 2000"))+1
This works fine provided EndMonthNumber is greater than StartMonthNumber, but what about the situation where StartMonthNumber is greater than EndMonthNumber... e.g., football from Sep (9) to Jan (1)? For this reason, the LET function includes instructions on how to make this assessment and what to do with the results:
Excel Formula:
IF(d<=0,12+d,d)
If StartMonthNumber is greater than EndMonthNumber, d will be negative, suggesting that we need the 12-complement, so the season length will be 12+d (d is negative). And if EndMonthNumber is greater than StartMonthNumber, d is taken as the season length. For example, football has StartMonthNumber=9 and EndMonthNumber=1, so 1-9+1=-7, a value <=0, therefore we compute d=12+(-7)=5...the football season is 5 months long.

I don't know if you are familiar with the LET function, but as shown here, it allows for the definition of one or more named variables (in this case "d" is defined as the function described above), and then that shorthand variable name can be used repeatedly later in the LET function (as shown in the IF function where d is needed three times). The final result returned by the LET function is the result produced by its last argument. To summarize then, SeasonLength in months is given by:
Excel Formula:
LET(d,MONTH(--($C3&" 1, 2000"))-MONTH(--($B3&" 1, 2000"))+1,IF(d<=0,12+d,d))

With these various building blocks, we can write a pseudo-formula for one part of the CF formula:
SEQUENCE(, SeasonLength, StartMonthNumber)
This generates an array consisting of a SeasonLength number of elements that begin at StartMonthNumber and increase by 1. For football, this array would be {9,10,11,12,13}...five elements beginning at 9 and increasing by 1.

Because we have crossed the year-to-year boundary (beyond 12 months), we feed this array into a MOD function that produces patterns of integers 1 through 12 (MOD returns the remainder of a number after division by the 2nd argument...12 in this case). To index the array correctly, 1 is subtracted initially before the mod operation and then 1 is added afterward.
Excel Formula:
MOD(SEQUENCE(, SeasonLength, StartMonthNumber)-1, 12) + 1
For the football season example, the evolution of the results looks like this:
MOD( {9,10,11,12,13} - 1, 12 ) + 1
MOD( {8,9,10,11,12}, 12 ) + 1
{8,9,10,11,0} + 1
{9,10,11,12,1}

The final result is an array of month numbers corresponding to the sport's season, so I'll refer to it as the SeasonMonthArray. Finally, this array is used in a MATCH function, where we attempt to find a match for the month number of each column heading (ColumnMonthNumber described earlier) in the SeasonMonthArray. If a MATCH is found--that is, the column heading represents a month falling within the sport's season--then a number will be returned. And if a match is not found, an error will be produced. So we wrap the entire MATCH function with an ISNUMBER function: if a match is found, ISNUMBER returns TRUE, otherwise FALSE.
Excel Formula:
=ISNUMBER( MATCH( ColumnMonthNumber, SeasonMonthArray, 0) )
 
Upvote 0
Starting with the column headings, we use a formula similar to your original one, except instead of referring to what is probably a helper row in your original sheet, the SEQUENCE function is used to create an array of 24 sequential numbers, starting with 0. This array is fed to the EDATE function, which will then produce an array representing representing today's date and sequential months. Those dates are fed into the TEXT function to return just the three-letter month abbreviations, which spill across the row.
Excel Formula:
TEXT(EDATE(TODAY(),SEQUENCE(,24,0)),"MMM")

For the Conditional Formatting (CF) function, it is easier to break it down into several parts:
Excel Formula:
=ISNUMBER(MATCH(MONTH(--(D$2&" 1, 2000")),MOD(SEQUENCE(,LET(d,MONTH(--($C3&" 1, 2000"))-MONTH(--($B3&" 1, 2000"))+1,IF(d<=0,12+d,d)),MONTH(--($B3&" 1, 2000")))-1,12)+1,0))

Somehow, the three-letter month abbreviations need to the expressed in terms of their month numbers. This can be done many different ways. I used a method that constructs a date from the month abbreviation by concatenating the month with a day (1) and a year (2000). The concatenation is still a text representation of the date, e.g., "Sep 1, 2000", so to coerce Excel to convert this to a numeric date value, the double unary operator (--) is used...and then the MONTH function will accept that numeric date as an argument. The choice of day number and year are arbitrary, as the MONTH function will return only the month number for whichever date is passed to it. Within the CF formula, you will see these components:
Excel Formula:
MONTH(--($B3&" 1, 2000"))   StartMonthNumber of season
Excel Formula:
MONTH(--($C3&" 1, 2000"))   EndMonthNumber of season
Excel Formula:
MONTH(--(D$2&" 1, 2000"))   ColumnMonthNumber of the 2-year calendar
...each returning a month number of the cell referenced. For example, if $B3 is Sep and $C3 is Jan, we'll get 9 and 1, the first two formulas will return 9 and 1.

Within the CF formula, these components are used for various purposes. In the LET function, we define the sport season durations (d) in terms of the difference between EndMonthNumber and StartMonthNumber (note 1 is added to account for both start and end months, and not just the intervals):
Excel Formula:
d, MONTH(--($C3&" 1, 2000")) - MONTH(--($B3&" 1, 2000"))+1
This works fine provided EndMonthNumber is greater than StartMonthNumber, but what about the situation where StartMonthNumber is greater than EndMonthNumber... e.g., football from Sep (9) to Jan (1)? For this reason, the LET function includes instructions on how to make this assessment and what to do with the results:
Excel Formula:
IF(d<=0,12+d,d)
If StartMonthNumber is greater than EndMonthNumber, d will be negative, suggesting that we need the 12-complement, so the season length will be 12+d (d is negative). And if EndMonthNumber is greater than StartMonthNumber, d is taken as the season length. For example, football has StartMonthNumber=9 and EndMonthNumber=1, so 1-9+1=-7, a value <=0, therefore we compute d=12+(-7)=5...the football season is 5 months long.

I don't know if you are familiar with the LET function, but as shown here, it allows for the definition of one or more named variables (in this case "d" is defined as the function described above), and then that shorthand variable name can be used repeatedly later in the LET function (as shown in the IF function where d is needed three times). The final result returned by the LET function is the result produced by its last argument. To summarize then, SeasonLength in months is given by:
Excel Formula:
LET(d,MONTH(--($C3&" 1, 2000"))-MONTH(--($B3&" 1, 2000"))+1,IF(d<=0,12+d,d))

With these various building blocks, we can write a pseudo-formula for one part of the CF formula:
SEQUENCE(, SeasonLength, StartMonthNumber)
This generates an array consisting of a SeasonLength number of elements that begin at StartMonthNumber and increase by 1. For football, this array would be {9,10,11,12,13}...five elements beginning at 9 and increasing by 1.

Because we have crossed the year-to-year boundary (beyond 12 months), we feed this array into a MOD function that produces patterns of integers 1 through 12 (MOD returns the remainder of a number after division by the 2nd argument...12 in this case). To index the array correctly, 1 is subtracted initially before the mod operation and then 1 is added afterward.
Excel Formula:
MOD(SEQUENCE(, SeasonLength, StartMonthNumber)-1, 12) + 1
For the football season example, the evolution of the results looks like this:
MOD( {9,10,11,12,13} - 1, 12 ) + 1
MOD( {8,9,10,11,12}, 12 ) + 1
{8,9,10,11,0} + 1
{9,10,11,12,1}

The final result is an array of month numbers corresponding to the sport's season, so I'll refer to it as the SeasonMonthArray. Finally, this array is used in a MATCH function, where we attempt to find a match for the month number of each column heading (ColumnMonthNumber described earlier) in the SeasonMonthArray. If a MATCH is found--that is, the column heading represents a month falling within the sport's season--then a number will be returned. And if a match is not found, an error will be produced. So we wrap the entire MATCH function with an ISNUMBER function: if a match is found, ISNUMBER returns TRUE, otherwise FALSE.
Excel Formula:
=ISNUMBER( MATCH( ColumnMonthNumber, SeasonMonthArray, 0) )
Thank KRice, that helps a ton and makes sense. I appreciate you taking the time and teaching.
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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