IF, but IF

qwzky

Board Regular
Joined
Jul 22, 2021
Messages
53
Office Version
  1. 2021
  2. 2016
Platform
  1. Windows
Hi! I am having a hard time figuring this out.
Maybe this is also about IFS function. My guess is that maybe it is also about COUNTIF.
Simply put, my problem looks like this:

1626994913106.png


I tried
Excel Formula:
=IFS(E2>10;"OK";IF(E2<10;"Work hard";"WORK HARD"); COUNTIF(B2:D2;"A"))

1626994775210.png


Please, help me with that. I really need that for my school as a principal.
 

Attachments

  • 1626993708778.png
    1626993708778.png
    29.8 KB · Views: 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Welcome to the MrExcel forum!

Try:

Book1
ABCDEF
1StudentGrade 1Grade 2Grade 3PointsResult
2Mark57914OK
3JohnA668Not OK
4BettyAA53Not OK
Sheet5
Cell Formulas
RangeFormula
F2:F4F2=IF(COUNTIF(B2:D2,"A"),"Not OK",IF(E2>10,"OK","Work hard"))



It looks like your version of Excel uses semi-colons instead of commas in the formula, make sure to change those when you enter it.
 
Upvote 0
Oh my, thank you :) I am so happy for this. Can you also please tell me what to do if I want to introduce multiple IFS in the green section?
For instance,

Excel Formula:
=IF(COUNTIF(B2:D2,"A"),"Not OK",[B][COLOR=rgb(65, 168, 95)]IF(E2>10,"OK","Work hard")) and/but if E2<5,"5",""[/COLOR][/B]
 
Upvote 0
I mean here:

=IF(COUNTIF(B2:D2,"A"),"Not OK",IF(E2>10,"OK","Work hard")) and/but if E2<5,"5",""
 
Upvote 0
When did you want it to be "" ?

Excel Formula:
=IF(COUNTIF(B2:D2,"A"),"Not OK",IF(E2>10,"OK",IF(E2>=5,"Work hard","5")))

I often use this layout you find it helps
Excel Formula:
=IF(COUNTIF(B2:D2,"A"),"Not OK",
    IF(E2>10,"OK",
        IF(E2>=5,"Work hard",
            "5")))

Alt+Enter gives you the new line and then just spaces for indenting
 
Upvote 0
With your help, I managed to come up with the solution:

Excel Formula:
=IF(COUNTIF(C6:E6;"A");"";IF(F6<=9;"10";IF(F6<=19;"9";IF(F6<29;"8";IF(F6<=39;"7";IF(F6<=49;"6";IF(F6<=59;"5";IF(F6<=69;"4";IF(F6<=79;"3";IF(F6<=89;"2";IF(F6<=300;"1";"")))))))))))

I understood that the FALSE is actually another IF (see below):

SC-uri automate REDONE.xlsm
CDEFGH
2Grade 1Grade 2Grade 3PointsResult
3579149
4A668 
5AA53 
6565555
Sheet2
Cell Formulas
RangeFormula
H3:H6H3=IF(COUNTIF(C3:E3,"A"),"",IF(F3<=9,"10",IF(F3<=19,"9",IF(F3<29,"8",IF(F3<=39,"7",IF(F3<=49,"6",IF(F3<=59,"5",IF(F3<=69,"4",IF(F3<=79,"3",IF(F3<=89,"2",IF(F3<=300,"1","")))))))))))
 
Upvote 0
At some point you might want to consider moving to using a lookup table.
The table can go anywhere in the workbook but the current vlookup formula needs it to be called tblGradeGrp.

Also I don't know if you realise it but your current If statement is returning the numbers as text by wrapping them in quote marks.
This means you can't use and arithmetic formulas on them eg you have "10" it is likely you just need 10.

20210723 Vlookup Grouping.xlsx
ABCDEFG
1
2Grade 1Grade 2Grade 3PointsResult
3579149
4A668 
5AA53 
6565555
7
8
9
10
11
12Grade Grouping
13Enter To column in ascending order
14TableNametblGradeGrp
15
16
17CalcInputInput
18
19FromToResult
200910
2110199
2220298
2330397
2440496
2550595
2660694
2770793
2880892
29903001
Sheet2
Cell Formulas
RangeFormula
G3:G6G3=IF(COUNTIF(C3:E3,"A"),"",VLOOKUP(F3,tblGradeGrp,3,TRUE))
A20:A29A20=IF(B19="To",0,N(B19)+1)
 
Upvote 0
I'm glad you got it worked out. Sometimes you can use one of the lookup functions to shorten the formula, like so:

Book1
CDEFG
2Grade 1Grade 2Grade 3PointsResult
3579149
4A668 
5AA53 
6565555
Sheet3
Cell Formulas
RangeFormula
G3:G6G3=IF(COUNTIF(C3:E3,"A"),"",LOOKUP(F3,{0,10,20,30,40,50,60,70,80,90,301},{10,9,8,7,6,5,4,3,2,1,""}))


It looks like Alex beat me to the punch. His formula uses an external table (arguably better), and my formula has it embedded within the formula.
 
Upvote 0
I'm glad you got it worked out. Sometimes you can use one of the lookup functions to shorten the formula, like so:

Book1
CDEFG
2Grade 1Grade 2Grade 3PointsResult
3579149
4A668 
5AA53 
6565555
Sheet3
Cell Formulas
RangeFormula
G3:G6G3=IF(COUNTIF(C3:E3,"A"),"",LOOKUP(F3,{0,10,20,30,40,50,60,70,80,90,301},{10,9,8,7,6,5,4,3,2,1,""}))


It looks like Alex beat me to the punch. His formula uses an external table (arguably better), and my formula has it embedded within the formula.
This formula doesn't seem to exclude the rows containing „A”. I tried to work around cell formatting as number, but it still doesn't work. You were right about it: I would like to use those results in calculating average. Can you think of a way to do modify the formula that I posted as a final solution?
 
Upvote 0
I am not sure Eric would still be online it is quite late where he is. I am in Australia.

This formula doesn't seem to exclude the rows containing „A”.

Eric's formula has exactly the same exclusion code as yours and I can confirm that it definitely returns "" if any of the Grades on that line have an "A" in them. ie =IF(COUNTIF(C3:E3,"A"),""

I tried to work around cell formatting as number, but it still doesn't work. You were right about it: I would like to use those results in calculating average. Can you think of a way to do modify the formula that I posted as a final solution?

As I pointed out earlier if you wanted to stick with your formula but have the results return numbers so you can work with them, all you need to do is remove the quote marks "" that you have around the numbers.
I have done that below.

Excel Formula:
    =IF(COUNTIF(C3:E3,"A"),"",IF(F3<=9,10,IF(F3<=19,9,IF(F3<29,8,IF(F3<=39,7,IF(F3<=49,6,IF(F3<=59,5,IF(F3<=69,4,IF(F3<=79,3,IF(F3<=89,2,IF(F3<=300,1,"")))))))))))
 
Upvote 0
Solution

Forum statistics

Threads
1,214,575
Messages
6,120,344
Members
448,956
Latest member
Adamsxl

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