If cell contains certain text, then return value

syang

New Member
Joined
Sep 21, 2013
Messages
21
I need help with this formula:

=IF(A1="Teacher","TEACHER","")&IF(B1="Student","STUDENT","")

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Teacher[/TD]
[TD][/TD]
[TD]TEACHER[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Student[/TD]
[TD]STUDENT[/TD]
[/TR]
[TR]
[TD]Teacher[/TD]
[TD]Student[/TD]
[TD]TEACHERSTUDENT[/TD]
[/TR]
</tbody>[/TABLE]

The first and second rows do what I need, but I want the last row to return "TEACHER, STUDENT" instead of "TEACHERSTUDENT."

Any help is appreciated...thank you!!
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
IF( AND( A1="Teacher", B1=Student) , "Teacher, Student", If( And(A1="Teacher",B1=""), "TEACHER", IF(And(A1="",B1="Student"), "STUDENT", "")))

 
Upvote 0
Thank you! It gave me an error but I made some revisions and it worked.

=IF(AND(A1="Teacher",B1="Student"), "TEACHER, STUDENT", IF(AND(A1="Teacher",B1=""), "TEACHER", IF(AND(A1="",B1="Student"), "STUDENT", "")))
 
Upvote 0
And one more option for you to consider...

=MID(IF(A1="","",", "&A1)&IF(B1="","",", "&B1),3,999)
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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