If 2 columns contain text from 2 ranges, insert text

chestnutgreen

New Member
Joined
Sep 13, 2023
Messages
2
Office Version
  1. 2016
Platform
  1. MacOS
Hello :) This is my first post. I've been a longtime lurker and always found what I needed without posting. But this time I've searched for a long time and tried different formulas without success.


I am trying to construct a formula that will return certain text based on the text in two columns. Each column is to be matched with a different named range.

For example: A3 contains "apple" and B3 contains "pasta". I want a formula for C3 that determines if A3 is from range F2:F4 (a list of fruit), and B3 is from range H2:H3 (a list of carbs), return text "Dinner".

Separately I would specify if the A value is from the carb range and the B value is from the protein language, the returned C text is "Lunch".

I would do this for about six conditions (eg Breakfast, Lunch, Snack, Dinner, Dessert, Midnight). Each range might have 20+ items.


I can do a simple evaluation based on one column but I have been frustrated trying to get one cell to evaluate two columns.
This works for one column:

=IF(COUNTIF(Fruit,A3),"Dinner","")

Screenshot attached - I can't get the mini-sheet to work with my older version of Excel.

Any help would be most appreciated.
 

Attachments

  • Screen Shot 2023-09-13 at 4.45.55 pm.png
    Screen Shot 2023-09-13 at 4.45.55 pm.png
    44.3 KB · Views: 15

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Like This ?


=LET(
FA,COUNTIF($F$2:$F$4,A3),
VA,COUNTIF($G$2:$G$5,A3),
CA,COUNTIF($H$2:$H$3,A3),
PA,COUNTIF($I$2:$I$3,A3),
FB,COUNTIF($F$2:$F$4,B3),
VB,COUNTIF($G$2:$G$5,B3),
CB,COUNTIF($H$2:$H$3,B3),
PB,COUNTIF($I$2:$I$3,B3),
IF(FA+CB>=2,"Dinner",IF(VA+CB>=2,"Lunch","Breakfast")))

Copy my Formula to Column C3, and u can add some Criteria ya :)


1694662052878.png
 
Upvote 0
@SunnyAlv
The OP's profile shows excel 2016 so they would not have the LET function.

@chestnutgreen
Welcome to the MrExcel board!

Could you use something like this?
I have assumed that any particular food item would appear in only one of the categories in columns F:I

23 09 14.xlsm
ABCDEFGHIJKL
1FruitVegetableCarbProteinComboMeal
2AppleTomatoPastaChickenFruit|Carb|FruitDinner
3ApplePastaDinnerBananaLettucePancakeBaconVegetable|Carb|VegetableLunch
4ApplePancakeDinnerPearBroccoliFruit|Vegetable|FruitBreakfast
5PearTomatoBreakfastCarrot
6BananaBacon??
7PastaChicken??
8PancakeCarrotLunch
Meals
Cell Formulas
RangeFormula
C3:C8C3=IFNA(INDEX(L$2:L$4,MATCH("*"&INDEX(F$1:I$1,SUMPRODUCT((F$2:I$100=A3)*(COLUMN(F$2:I$2)-COLUMN(F$2)+1)))&"|"&INDEX(F$1:I$1,SUMPRODUCT((F$2:I$100=B3)*(COLUMN(F$2:I$2)-COLUMN(F$2)+1)))&"*",K$2:K$4,0)),"??")
 
Last edited:
Upvote 0
@SunnyAlv
Thank you - LET would be good to try. I might just finally have to get around to updating to 365. Hope Microsoft has you on commission ;)

@Peter_SSs
Brilliant - it works and I've been able to adapt it, although I'm still learning all the parameters. Thank you for going to such detail to make this work - much appreciated.
To answer your question, yes - each item will appear only once in the index.

When there are items in column A *and* B that do not appear at all in the index, the formula gives me #VALUE! How can I adopt the formula so it gives no return or error?
When there is an item in column A *or* B that does not appear in the index, in the formula I've replaced "??" with "" and that has worked.

Thank you again to you both.
 
Upvote 0
Would something like this be suitable then?

23 09 14.xlsm
ABCDEFGHIJKL
1FruitVegetableCarbProteinComboMeal
2AppleTomatoPastaChickenFruit|Carb|FruitDinner
3ApplePastaDinnerBananaLettucePancakeBaconVegetable|Carb|VegetableLunch
4ApplePancakeDinnerPearBroccoliFruit|Vegetable|FruitBreakfast
5PearTomatoBreakfastCarrotx|y 
6SaltPepper 
7SaltPasta 
8PastaSalt 
9PastaChicken 
10PancakeCarrotLunch
Meals (2)
Cell Formulas
RangeFormula
L5L5=""
C3:C10C3=IFNA(INDEX(L$2:L$5,MATCH("*"&IF(COUNTIF(F$2:I$100,A3)=1,INDEX(F$1:I$1,SUMPRODUCT((F$2:I$100=A3)*(COLUMN(F$2:I$2)-COLUMN(F$2)+1))),"x")&"|"&IF(COUNTIF(F$2:I$100,B3)=1,INDEX(F$1:I$1,SUMPRODUCT((F$2:I$100=B3)*(COLUMN(F$2:I$2)-COLUMN(F$2)+1))),"y")&"*",K$2:K$5,0)),"")
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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