Condition a cell result based on rows value

Dani_LobP

Board Regular
Joined
Aug 16, 2019
Messages
134
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm struggling to make a condition to a value to show a result based on the value of rows below in the same column.

The idea is to give either R, A or G result, based on what is below.

So if i have X amount of rows below, and each one has different values in combinations of R, A and G, the top row will display the summary lets say.
Is some kind of take worst case scenario, since R is Red, A amber and G green.

Condition is as follow:
- as long as there is 1 R in the rows, main result will be R.
- if there is no R at all, but they are mix of A and G, then main result will be A.
- if ALL are G, then main result will be G.

R#N/A -> should be AG
ex1GGG
ex2AAG
ex3GGG
ex4GGG
ex5AAG
ex6AAG
ex7GGG
ex8RAG
ex9AAG
ex10RGG

Code i am using on the fist top row:
VBA Code:
=IF(AND(B2="G",B3="G",B4="G",B5="G",B6="G",B7="G",B8="G",B9="G",B10="G",B11="G"),
"G",
IF(MATCH("R",B2:B11,0),
"R",
IF(OR(B2="A",B3="A",B4="A",B5="A",B6="A",B7="A",B8="A",B9="A",B10="A",B11="A"),"A")))

For some reason I manage to make it work for when there is at least 1 R, and when all is G.. A is what i don't seem to understand why is not working.

Thanks in advance!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
did you want VBA code
a function
using Countif

=Countif($B$2:$B$100, "R")>0
=Countif($B$2:$B$100, "A")>0
combined in an IF

=IF(COUNTIF($B$2:$B$100,"R")>0,"R",IF(COUNTIF($B$2:$B$100,"A")>0,"A","G")

if the range is blank , then it will be green
But we could avoid that if necessary

Change the range to match you data

Book1
BCD
1RAG
2aag
3rgg
4gag
Sheet1
Cell Formulas
RangeFormula
B1B1=IF(COUNTIF($B$2:$B$100,"R")>0,"R",IF(COUNTIF($B$2:$B$100,"A")>0,"A","G") )
C1C1=IF(COUNTIF($C$2:$C$100,"R")>0,"R",IF(COUNTIF($C$2:$C$100,"A")>0,"A","G") )
D1D1=IF(COUNTIF($D$2:$D$100,"R")>0,"R",IF(COUNTIF($D$2:$D$100,"A")>0,"A","G") )
 
Upvote 0
Solution
did you want VBA code
a function
using Countif

=Countif($B$2:$B$100, "R")>0
=Countif($B$2:$B$100, "A")>0
combined in an IF

=IF(COUNTIF($B$2:$B$100,"R")>0,"R",IF(COUNTIF($B$2:$B$100,"A")>0,"A","G")

if the range is blank , then it will be green
But we could avoid that if necessary

Change the range to match you data

Book1
BCD
1RAG
2aag
3rgg
4gag
Sheet1
Cell Formulas
RangeFormula
B1B1=IF(COUNTIF($B$2:$B$100,"R")>0,"R",IF(COUNTIF($B$2:$B$100,"A")>0,"A","G") )
C1C1=IF(COUNTIF($C$2:$C$100,"R")>0,"R",IF(COUNTIF($C$2:$C$100,"A")>0,"A","G") )
D1D1=IF(COUNTIF($D$2:$D$100,"R")>0,"R",IF(COUNTIF($D$2:$D$100,"A")>0,"A","G") )
No, was not looking for VBA but just a simple formula, what you shared is somehow working better than the path I chose :D thanks a lot for the help!
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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