Conditionally format column based on 2 other columns

honkin

Active Member
Joined
Mar 20, 2012
Messages
374
Office Version
  1. 2016
Platform
  1. MacOS
I need to conditionally format a column based on the text in 2 other columns and am just wondering what the best way to reference the entire columns in my formula would be

Here is the code as it stands

=AND(A1="MARIA1",C1="PORTUGAL: Segunda Liga")

So if I wanted it to apply to all of A and all of C, would I just change it to be A:A and C:C? I didn't want to use C2:C1048576 if possible. The CF will then highlight entries in E, so I assume I would have the range as E:E

And I guess if I want those same columns to look for different text, I would need a different rule for each condition yeah? As an example, a cell in A might have MARIA10 and a cell in C might have Italy: Serie A and so on

cheers
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
No, you leave the formula as it is & it should work.

Depends on whether you want different colours or not & what your exact requirements are.
cheers Fluff and thanks for getting back to me. That wasn't the answer I was expecting, though, as A1 and C1 are specific cells, so I am struggling to see how a formula done that way will handle ALL of column A and C with the CF being applied in E. Surely it will only be looking at A1 & C1, which was the reason for my post.

I may not have been clear in my initial post; the ultimate aim is that any time those two text references appear in any row in A & C, the corresponding cell in E will have CF applied.

To elaborate further, I was also considering doing it all in VBA, as the initial post simply listed just the single text in A & C, but the reality is, there will be possible 20 or more entries which will have MARIA1 in A and varying things in C and all will need the CF applied. On top of that, the MARIA entries will go from 1 to 10 and each of them will have 20 or more leagues mentioned, so there could be upwards of 200 variations of leagues for MARIA (1-10)

In your experience, is that getting a little messy to be done in CF and would it be better handled by a single VBA macro listing all the MARIAs from 1 to 10 and the possible array of league combinations which would then need to have CF in column E?

This has been autofiltered just so you can see what I mean.

Predictology-Reports Football Advisor.xlsx
ABCDE
901MARIA330/04/2022 20:30Egypt: Premier LeagueLayWinCeramica Cleopatra - Al Ahly
907MARIA201/05/2022 01:00Argentina: Primera B NacionalLayWinInstituto - Tristan Suarez
909MARIA301/05/2022 01:00Argentina: Primera B NacionalLayWinInstituto - Tristan Suarez
910MARIA1001/05/2022 01:00Argentina: Primera B NacionalLayWinInstituto - Tristan Suarez
919MARIA1001/05/2022 17:30Serbia: Super LigaLayWinBacka Topola - Vozdovac
922MARIA201/05/2022 18:00Czech Republic: Czech LigaLayWinSlavia Praha - Viktoria Plzen
924MARIA301/05/2022 18:00Czech Republic: Czech LigaLayWinSlavia Praha - Viktoria Plzen
925MARIA1001/05/2022 18:00Czech Republic: Czech LigaLayWinSlavia Praha - Viktoria Plzen
935MARIA1002/05/2022 17:30Serbia: Super LigaLayWinCukaricki - Radnicki Nis
940Maria102/05/2022 19:45France: Ligue 2LayDrawRodez - Toulouse
942MARIA202/05/2022 20:00Spain: SegundaLayWinValladolid - Real Sociedad II
944MARIA302/05/2022 20:00Spain: SegundaLayWinValladolid - Real Sociedad II
945MARIA1002/05/2022 20:00Spain: SegundaLayWinValladolid - Real Sociedad II
950MARIA704/05/2022 16:00Slovakia: Fortuna ligaLayWinRuzomberok - Zilina
952MARIA206/05/2022 16:30Czech Republic: 2. Liga FNLLayWinVlasim - Trinec
954MARIA306/05/2022 16:30Czech Republic: 2. Liga FNLLayWinVlasim - Trinec
956MARIA406/05/2022 16:30Czech Republic: 2. Liga FNLLayWinVlasim - Trinec
959MARIA206/05/2022 18:00Denmark: SuperligaLayWinSilkeborg - Randers
961MARIA306/05/2022 18:00Denmark: SuperligaLayWinSilkeborg - Randers
963MARIA406/05/2022 18:00Denmark: SuperligaLayWinSilkeborg - Randers
965MARIA706/05/2022 18:30Switzerland: Challenge LeagueLayWinFC Schaffhausen - Kriens
967MARIA206/05/2022 19:30Italy: Serie BLayWinAscoli - Ternana
969MARIA306/05/2022 19:30Italy: Serie BLayWinAscoli - Ternana
971MARIA406/05/2022 19:30Italy: Serie BLayWinAscoli - Ternana
973MARIA206/05/2022 19:30Italy: Serie BLayWinBenevento - Spal
975MARIA306/05/2022 19:30Italy: Serie BLayWinBenevento - Spal
977MARIA406/05/2022 19:30Italy: Serie BLayWinBenevento - Spal
978MARIA206/05/2022 19:30Italy: Serie BLayWinComo - Cremonese
979MARIA306/05/2022 19:30Italy: Serie BLayWinComo - Cremonese
989MARIA407/05/2022 12:30Ger. Bundesliga IILayWinHamburg - Hannover
990Maria607/05/2022 13:00Austria: 2. LigaLayWinGrazer AK - Dornbirn
991MARIA107/05/2022 14:00Portugal: Segunda LigaLayDrawSporting Covilha - Rio Ave
Maria Lay
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E:EExpression=AND(A1047542="MARIA10",C1047542="Sco. Premiership")textNO
E:EExpression=AND(A1="MARIA1",C1="PORTUGAL: Segunda Liga")textNO


cheers
 
Upvote 0
As the A1 & C1 are both relative the CF will work for all rows as can be seen here.
+Fluff 1.xlsm
ABCDE
1MARIA344681.8542Egypt: Premier LeagueLayWinCeramica Cleopatra - Al Ahly
2MARIA244682.0417Argentina: Primera B NacionalLayWinInstituto - Tristan Suarez
3MARIA344682.0417Argentina: Primera B NacionalLayWinInstituto - Tristan Suarez
4MARIA1044682.0417Argentina: Primera B NacionalLayWinInstituto - Tristan Suarez
5MARIA1044682.7292Serbia: Super LigaLayWinBacka Topola - Vozdovac
6MARIA244682.75Czech Republic: Czech LigaLayWinSlavia Praha - Viktoria Plzen
7MARIA344682.75Czech Republic: Czech LigaLayWinSlavia Praha - Viktoria Plzen
8MARIA1044682.75Czech Republic: Czech LigaLayWinSlavia Praha - Viktoria Plzen
9MARIA1044683.7292Serbia: Super LigaLayWinCukaricki - Radnicki Nis
10Maria144683.8229France: Ligue 2LayDrawRodez - Toulouse
11MARIA244683.8333Spain: SegundaLayWinValladolid - Real Sociedad II
12MARIA344683.8333Spain: SegundaLayWinValladolid - Real Sociedad II
13MARIA1044683.8333Spain: SegundaLayWinValladolid - Real Sociedad II
14MARIA744685.6667Slovakia: Fortuna ligaLayWinRuzomberok - Zilina
15MARIA244687.6875Czech Republic: 2. Liga FNLLayWinVlasim - Trinec
16MARIA344687.6875Czech Republic: 2. Liga FNLLayWinVlasim - Trinec
17MARIA444687.6875Czech Republic: 2. Liga FNLLayWinVlasim - Trinec
18MARIA244687.75Denmark: SuperligaLayWinSilkeborg - Randers
19MARIA344687.75Denmark: SuperligaLayWinSilkeborg - Randers
20MARIA444687.75Denmark: SuperligaLayWinSilkeborg - Randers
21MARIA744687.7708Switzerland: Challenge LeagueLayWinFC Schaffhausen - Kriens
22MARIA244687.8125Italy: Serie BLayWinAscoli - Ternana
23MARIA344687.8125Italy: Serie BLayWinAscoli - Ternana
24MARIA444687.8125Italy: Serie BLayWinAscoli - Ternana
25MARIA244687.8125Italy: Serie BLayWinBenevento - Spal
26MARIA344687.8125Italy: Serie BLayWinBenevento - Spal
27MARIA444687.8125Italy: Serie BLayWinBenevento - Spal
28MARIA244687.8125Italy: Serie BLayWinComo - Cremonese
29MARIA344687.8125Italy: Serie BLayWinComo - Cremonese
30MARIA444688.5208Ger. Bundesliga IILayWinHamburg - Hannover
31Maria644688.5417Austria: 2. LigaLayWinGrazer AK - Dornbirn
32MARIA144688.5833Portugal: Segunda LigaLayDrawSporting Covilha - Rio Ave
Main
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E:EExpression=AND(A1="Maria2",C1="Italy: Serie B")textNO


With ~200 different variations, I would go with VBA rather than CF.
 
Upvote 0
As the A1 & C1 are both relative the CF will work for all rows as can be seen here.
+Fluff 1.xlsm
ABCDE
1MARIA344681.8542Egypt: Premier LeagueLayWinCeramica Cleopatra - Al Ahly
2MARIA244682.0417Argentina: Primera B NacionalLayWinInstituto - Tristan Suarez
3MARIA344682.0417Argentina: Primera B NacionalLayWinInstituto - Tristan Suarez
4MARIA1044682.0417Argentina: Primera B NacionalLayWinInstituto - Tristan Suarez
5MARIA1044682.7292Serbia: Super LigaLayWinBacka Topola - Vozdovac
6MARIA244682.75Czech Republic: Czech LigaLayWinSlavia Praha - Viktoria Plzen
7MARIA344682.75Czech Republic: Czech LigaLayWinSlavia Praha - Viktoria Plzen
8MARIA1044682.75Czech Republic: Czech LigaLayWinSlavia Praha - Viktoria Plzen
9MARIA1044683.7292Serbia: Super LigaLayWinCukaricki - Radnicki Nis
10Maria144683.8229France: Ligue 2LayDrawRodez - Toulouse
11MARIA244683.8333Spain: SegundaLayWinValladolid - Real Sociedad II
12MARIA344683.8333Spain: SegundaLayWinValladolid - Real Sociedad II
13MARIA1044683.8333Spain: SegundaLayWinValladolid - Real Sociedad II
14MARIA744685.6667Slovakia: Fortuna ligaLayWinRuzomberok - Zilina
15MARIA244687.6875Czech Republic: 2. Liga FNLLayWinVlasim - Trinec
16MARIA344687.6875Czech Republic: 2. Liga FNLLayWinVlasim - Trinec
17MARIA444687.6875Czech Republic: 2. Liga FNLLayWinVlasim - Trinec
18MARIA244687.75Denmark: SuperligaLayWinSilkeborg - Randers
19MARIA344687.75Denmark: SuperligaLayWinSilkeborg - Randers
20MARIA444687.75Denmark: SuperligaLayWinSilkeborg - Randers
21MARIA744687.7708Switzerland: Challenge LeagueLayWinFC Schaffhausen - Kriens
22MARIA244687.8125Italy: Serie BLayWinAscoli - Ternana
23MARIA344687.8125Italy: Serie BLayWinAscoli - Ternana
24MARIA444687.8125Italy: Serie BLayWinAscoli - Ternana
25MARIA244687.8125Italy: Serie BLayWinBenevento - Spal
26MARIA344687.8125Italy: Serie BLayWinBenevento - Spal
27MARIA444687.8125Italy: Serie BLayWinBenevento - Spal
28MARIA244687.8125Italy: Serie BLayWinComo - Cremonese
29MARIA344687.8125Italy: Serie BLayWinComo - Cremonese
30MARIA444688.5208Ger. Bundesliga IILayWinHamburg - Hannover
31Maria644688.5417Austria: 2. LigaLayWinGrazer AK - Dornbirn
32MARIA144688.5833Portugal: Segunda LigaLayDrawSporting Covilha - Rio Ave
Main
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E:EExpression=AND(A1="Maria2",C1="Italy: Serie B")textNO


With ~200 different variations, I would go with VBA rather than CF.
Cheers Fluff. Apologies for the delay. OK, understood re the relative references.

Yes, I feared VBA would be the way. Just unsure how to target 2 different ranges with the conditions and then have the resulting format occur in a 3rd range

I am wanting to target the entire columns of both A & C for the conditions, but I guess I will need to have them as separate ranges, due to different content being in each column? A is the name of the model and C is the name of the league. E is the match and it is this column which will be coloured.

So to set 2 separate ranges, would it be something like the following?

VBA Code:
Dim ModelRange As Range1
Dim LeagueRange As Range2
Set ModelRange = Range("A:A")
Set LeagueRange = Range("C:C")

Just trying to get my head around this part first.

And for the conditions, is this heading in the right direction?

Rich (BB code):
Range1.FormatConditions.Add Type:=xlCellValue, Operator:=xlFilterValues, _
        Formula1:="=LTD1"
Range2.FormatConditions.Add Type:=xlCellValue, Operator:=xlFilterValues, _
        Formula1:="=Lithuania: A Lyga"

So a quick question. How do I now target Range1 and Range 2 together so that if both conditions are met, the cell in column E is coloured accordingly?

Can I also assume that to have multiple leagues for Range2, that an array would be needed? There are maybe 20 leagues just for the LTD1 model. Some will be required to be coloured one shade of green and the rest a different shade of green.

cheers Fluff. Just trying to slowly work my way through each element.
 
Upvote 0
With approx 200 different conditions, using CF is likely to slow the workbook down considerably. You maybe better off just using VBA to colour the cells, rather than to apply CF.
 
Upvote 0
With approx 200 different conditions, using CF is likely to slow the workbook down considerably. You maybe better off just using VBA to colour the cells, rather than to apply CF.
cheers Fluff. My last post above was an attempt to seek advice on creating the VBA code to do that, as it is a bit beyond me.

I mean, I guess I could possibly use autofiltering for some of it; the model name (A) and the league (C), though C would have possibly 20 possibilities, not just the 3 as below.

.AutoFilter Field:=1, Criteria1:="*LTD1*"
.AutoFilter Field:=3, Criteria1:=Array("Portugal: Primeira Liga", "Italy: Serie A", "Hungary: NB I"), Operator:=xlFilterValues

But then how to have column E be coloured if both the first and second autofilter criteria match?

I also guess I could have a separate VBA macro for each model, so rather than 200 possible combinations, for LTD1, there would be only 20.

Other than that I'm a bit stumped as to how to achieve it
 
Upvote 0
You could use
VBA Code:
   With ActiveSheet
      .Range("A1").AutoFilter 1, "*LTD1*"
      .Range("A1").AutoFilter 3, Array("Portugal: Primeira Liga", "Italy: Serie A", "Hungary: NB I"), xlFilterValues
      .AutoFilter.Range.Offset(1).Columns(5).Interior.Color = 5296274
      .AutoFilterMode = False
      .Range("E" & rows.Count).End(xlUp).Offset(1).Interior.Color = xlNone
   End With
 
Upvote 0
You could use
VBA Code:
   With ActiveSheet
      .Range("A1").AutoFilter 1, "*LTD1*"
      .Range("A1").AutoFilter 3, Array("Portugal: Primeira Liga", "Italy: Serie A", "Hungary: NB I"), xlFilterValues
      .AutoFilter.Range.Offset(1).Columns(5).Interior.Color = 5296274
      .AutoFilterMode = False
      .Range("E" & rows.Count).End(xlUp).Offset(1).Interior.Color = xlNone
   End With
Howdy Fluff

Sincere apologies with this. I completely lost track of this post and just discovered it again. I have been spending countless hours each week still manually colouring the cells, so a timely discovery I hope.
I think I need to actually name the sheet rather than just saying ActiveSheet, if that makes sense. There are 10 sheets in this workbook and each sheet will need its own VBA to do the colouring.

So what I currently have setup with the workbook is the ability to run a handful of macros which open all the files in the relevant folder for each sheet and copy all the selections t the sheet, adding the system name in the process. That part is great and saves me loads of time. What I'd like now is for the individual macro to then call the VBA for that sheet, automatically colouring the cell with the match details.

This is an example of the macro that handles the LTD model

VBA Code:
Sub Open_All_Files_LTD()
Dim sFil As String
Dim sPath As String

sPath = "/Users/sos/Documents/Football Advisor/New Role/Predictology/Lay The Draw/" 'location of files
ChDir sPath
sFil = Dir("")
Do While sFil <> ""
Workbooks.Open FileName:=sPath & sFil
Call LAY_THE_DRAW_Weekly
sFil = Dir
Loop
End Sub

Once that has finished opening and copying all the matches to the Lay The Draw sheet, I want it to then proceed colouring the matches. The colour I have been using in the sheet is RGB 146, 208, 79 which is Hex #92D04F

Just the LTD model on its own has 36 different systems supplying selections, all with varying number of leagues in them. Do you believe I will need to create a separate VBA module for each of the 36, or is there a way to create a centralised sort of index (not sure if that is the right term, but I'm sure you get the gist)? Like a record listing all the models, leagues and colours.

Here is an example of the leagues just in the LTD1_HOME model which will need to be coloured
Austria: 2. Liga
Australia: A-League
Bulgaria: Parva Liga
Czech Republic: Czech Liga
Denmark: Superliga
Germany: Bundesliga II
Greece: Superleague
Hungary: NB I
Portugal: Primeira Liga
Portugal: Segunda Liga
Poland: Ekstraklasa
Qatar: Q League
Turkey: Super Lig

The names of the leagues are listed exactly as they come in from the data supplier. So with 36 of these models, what would be my best approach to list all the leagues and the colour required (most require the green I listed above, though a handful require RGB 183 222 232 Hex #B7DEE8). All models will be a similar approach.

I don't have an issue creating 36 separate VBA macros (once I can sus the required code) and possibly have something which calls them one after the other, but if there is a way to use a central record of all models and their leagues and colour and that can be referenced in a single VBA macro, happy to go that route instead. I'm just unsure of the best approach.

Thanks so much for your time
 
Upvote 0
As this is now a significantly different question, you need to start a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

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