Search and return matches into multiple columns

RowanW

New Member
Joined
Dec 16, 2019
Messages
1
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi All

I have a scenario where I'm attempting to extract certain words that appear between double quotes but only if they meet a certain condition.

For example I want to search for ALL fruit in column A and present these individually in the subsequent columns.

Fruit' = "Pear" OR 'Fruit' = "Apple" AND 'Vegetable' = "Cabbage" AND 'Meat' = "Beef"

So for the above, it would return "Pear" in Column B and Apple in Column C (ignoring all of the other items that are not fruit)

Any idea how I would go about this? (Ideally an excel formula as my skills in VBA are at level 1)
 

Attachments

  • Fruit screenshot.PNG
    Fruit screenshot.PNG
    20.6 KB · Views: 15

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I've written UDF like this:

Code:
Function GetFruits(MyStr As String, MyEl As Long) As String
Dim temp1 As Variant
Dim temp2 As String
Dim i As Long
temp1 = Split(MyStr, " ")
For i = LBound(temp1) To UBound(temp1)
    If temp1(i) = "Fruit'" Or temp1(i) = "'Fruit'" Then temp2 = temp2 & temp1(i + 2) & ","
Next i
temp1 = Split(temp2, ",")
On Error GoTo MyError
GetFruits = Replace(temp1(MyEl - 1), """", "")
Exit Function
MyError:
GetFruits = ""
End Function

then into B2:

Code:
=GetFruits($A2,COLUMN()-1)

and drag it right/down as needed.


A
B
C
Fruit' = "Pear" OR 'Fruit' = "Apple" AND 'Vegetable' = "Cabbage" AND 'Meat' = "Beef"PearApple


A
B
C
Fruit' = "Pear" OR 'Fruit' = "Apple" AND 'Vegetable' = "Cabbage" AND 'Meat' = "Beef"=GetFruits($A2,COLUMN()-1)=GetFruits($A2,COLUMN()-1)
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

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