Home

Searching for text

%3CLINGO-SUB%20id%3D%22lingo-sub-720437%22%20slang%3D%22en-US%22%3ESearching%20for%20text%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-720437%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20trying%20to%20create%20a%20function%20of%20the%20following%20thing%3A%3C%2FP%3E%3CP%3ESearch%20on%20the%20sheet%20%222%22%2C%20in%20a%20column%20%22B%22%20(where%20exist%20a%20bunch%20of%20cells%20full%20of%20text)%20a%20cell%20that%20contains%20info%20from%202%20cells%20from%20sheet%20%221%22%20in%20columns%20%22A%22%20and%20%22B%22.%20For%20example%3A%20On%20sheet%20%221%22%20a%20have%201%20cell%20with%20%22Apple%22%20and%20the%20second%20cell%20with%20%22Pear%22%2C%20and%20i%20need%20to%20find%20on%20sheet%20%222%22%20column%20%22B%22%2C%20a%20recipe%20that%20contains%20%22Apple%22%20and%20%22Pear%22%20(those%20words%20coming%20from%20the%20two%20cells%20from%20sheet%201)%2C%20even%20if%20those%20two%20words%20are%20separated%20inside%20the%20cell%20on%20sheet%20%22B%22.%26nbsp%3B%20Then%20create%20a%20drop%20down%20with%20the%20results%20of%20the%20search%20previously%20made.%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20attaching%202%20files%20with%20this%20example%20to%20make%20it%20easier%20to%20understand%20the%20idea.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-720437%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-720648%22%20slang%3D%22en-US%22%3ERe%3A%20Searching%20for%20text%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-720648%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366570%22%20target%3D%22_blank%22%3E%40ArthurADs%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%3C%2FP%3E%3CP%3EYour%20request%20is%20simple%20%2C%20however%20you%20have%20multiple%20issues%20with%20the%20setup%3A%3C%2FP%3E%3CP%3E1-%20These%20are%20not%20two%20%22Sheets%22%2C%20these%20are%202%20separate%20Files%20%22Workbooks%22.%20which%20is%20NOT%20an%20ideal%20option.%20Better%20have%20the%20source%20data%20(recipes)%2C%20Your%20Conditions(Apple%2C%20Pear%2C...)%20and%20the%20final%20result%20used%20for%20creating%20drop%20lists%20into%20one%20single%20Excel%20file.%3C%2FP%3E%3CP%3E2-%20The%20data%20where%20we%20search%20would%20better%20be%20split%20into%202%20columns%20say%3A%20Recipe%20name%20%26amp%3B%20Recipe%20details%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOnce%20you%20have%20a%20much%20better%20setup%2C%20tens%20or%20hundreds%20of%20recipes%2C%20and%20assuming%20that%20you%20will%20always%20search%20using%202%20conditions%20(not%20necessary%20Apple%20%26amp%3B%20Pear)%20then%20the%20steps%20are%20as%20follows%3A%3C%2FP%3E%3CP%3E1-%20Create%20a%20search%20function%20that%20searches%20for%20the%20keywords%3C%2FP%3E%3CP%3E2-%20Create%20an%20Advanced%20Filter%20(Data%20Tab%20%26gt%3B%26gt%3B%20Advanced)%3C%2FP%3E%3CP%3E3-%20Run%20the%20filter%20automatically%20every%20time%20the%20search%20term%20changes%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20attaching%20a%20sample%20file%20with%20different%20data%20where%20we%20want%20to%20extract%20records%20based%20on%202%20conditions%20selected%20from%202%20drop%20lists%20'region%22%20%26amp%3B%20%22Sales%20Rep%22%3C%2FP%3E%3CP%3Ethis%20is%20exactly%20what%20you%20need.%20Test%20by%20changing%20the%20Region%20or%20Sales%20Rep%20from%20their%20drop%20lists%3C%2FP%3E%3CP%3ENote%20%3A%20the%20source%20list%20(like%20your%20Recipes)%20is%20in%20columns%20A%3AF%3CBR%20%2F%3EThe%20conditions%20(drop%20lists)%20are%20in%20Cells%20H2%20%26amp%3B%20I2%3CBR%20%2F%3EThe%20extracted%20records%20are%20in%20columns%20K%20to%20P%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Elet%20me%20help%20you%20with%20an%20action%20Plan%3A%3CBR%20%2F%3ETry%20to%20create%20a%20list%20of%20Recipes%20more%20organized%20and%20split%20the%20data%20into%20columns%2C%20Having%20Headers%20such%20as%3A%20recipe%20code%2C%20Recipe%20Name%2C%20Ingredients%2C%20How%20to%20prepare...etc%3C%2FP%3E%3CP%3ECreate%202%20lists%20with%20the%20different%20ingredients%20you%20will%20look%20for.%3CBR%20%2F%3Ei%20can%20then%20help%20you%20create%20the%20functionality.%3C%2FP%3E%3CP%3Ea%20friendly%20advice%2C%20do%20not%20use%20Excel%20with%20the%20same%20approach%20we%20use%20a%20word%20editor.%20break%20the%20data%20so%20that%20Excel%20can%20help%20you%20extract%20records.%3C%2FP%3E%3CP%3EGood%20Luck%3C%2FP%3E%3CP%3ENabil%20Mourad%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-721068%22%20slang%3D%22en-US%22%3ERe%3A%20Searching%20for%20text%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-721068%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366570%22%20target%3D%22_blank%22%3E%40ArthurADs%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Arthur%2C%3C%2FP%3E%3CP%3Ei%20have%20managed%20to%20get%20list%20with%20recipes%2C%20take%20a%20loom%20at%20the%20attachment.%20Is%20you%20enter%20column%20A%20or%20column%20B%20the%20list%20will%20be%20generated%20automatically.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3CBR%20%2F%3EDim%20lngRow%20As%20Long%3CBR%20%2F%3EDim%20lngRowMax%20As%20Long%3CBR%20%2F%3EDim%20strBuf%20As%20String%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20Target.Column%20%26lt%3B%203%20Then%3CBR%20%2F%3E%3CBR%20%2F%3EWith%20Cells(Target.Row%2C%203).Validation%3CBR%20%2F%3E.Delete%3CBR%20%2F%3ElngRowMax%20%3D%20Sheet2.Range(%22B%22%20%26amp%3B%20Sheet2.Rows.Count).End(xlUp).Row%3CBR%20%2F%3EFor%20lngRow%20%3D%202%20To%20lngRowMax%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20InStr(LCase(Sheet2.Range(%22B%22%20%26amp%3B%20lngRow).Value)%2C%20LCase(Cells(Target.Row%2C%201).Value))%20%26gt%3B%200%20And%20_%3CBR%20%2F%3EInStr(LCase(Sheet2.Range(%22B%22%20%26amp%3B%20lngRow).Value)%2C%20LCase(Cells(Target.Row%2C%202).Value))%20%26gt%3B%200%20Then%3CBR%20%2F%3E%3CBR%20%2F%3EstrBuf%20%3D%20strBuf%20%26amp%3B%20Sheet2.Range(%22B%22%20%26amp%3B%20lngRow).Value%20%26amp%3B%20%22-%22%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3E%3CBR%20%2F%3ENext%20lngRow%3CBR%20%2F%3E%3CBR%20%2F%3EstrBuf%20%3D%20Left(strBuf%2C%20Len(strBuf)%20-%201)%3CBR%20%2F%3EstrBuf%20%3D%20Replace(strBuf%2C%20%22%3B%22%2C%20%22.%22)%3CBR%20%2F%3EstrBuf%20%3D%20Replace(strBuf%2C%20%22.%22%2C%20%22.%22)%3CBR%20%2F%3EstrBuf%20%3D%20Replace(strBuf%2C%20%22%2C%22%2C%20%22.%22)%3CBR%20%2F%3EstrBuf%20%3D%20Replace(strBuf%2C%20%22-%22%2C%20%22%2C%22)%3CBR%20%2F%3E%3CBR%20%2F%3E.Add%20Type%3A%3DxlValidateList%2C%20AlertStyle%3A%3DxlValidAlertInformation%2C%20Operator%3A%3DxlBetween%2C%20Formula1%3A%3DstrBuf%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3E%3CBR%20%2F%3EEnd%20Sub%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%20regards%26nbsp%3B%3C%2FP%3E%3CP%3EBernd%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fvba-tanker.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fvba-tanker.com%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-722059%22%20slang%3D%22en-US%22%3ERe%3A%20Searching%20for%20text%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722059%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F365248%22%20target%3D%22_blank%22%3E%40nabilmourad%3C%2FA%3E%26nbsp%3BHey%2C%20thanks%20for%20your%20correction%20related%20to%20the%20%22Sheets%22%2C%20haha%2C%20I'm%20pretty%20new%20on%20excel%20universe%2C%20and%20thanks%20for%20you%20suggestion.%20Your%20file%20is%20incredible%2C%20but%20it%20doesn't%20solve%20my%20problem%2C%20unfortunetaly.%20The%20problem%20is%2C%20there%20is%20already%20a%20file%20with%20all%20the%20data%20related%20to%20the%20recipes%2C%20with%20the%20following%20headers%3A%20Recipe%20Name%2C%20Author%2C%26nbsp%3BDescriptions%2C%20Ingredients%20and%20finally%20How%20to%20do%20it%20(the%20data%20that%20exist%20on%20%22Sheet%202%22%20attached%20in%20my%20post).%20Since%20the%20data%20%22Apple%22%20and%20%22Pear%22%2C%20are%20surronded%20by%20a%20bunch%20of%20text%20in%20a%20single%20cell%20inside%20the%20column%20%22How%20to%20do%20it%22%2C%20i%20would%20need%20a%20function%20that%20is%20able%20to%20search%20in%20those%20cells%20(Column%20%22How%20to%20do%20it%22)%20those%20two%20words%20%22Apple%22%20and%20%22Pear%22%2C%20even%20if%20they%20are%20not%20close%20to%20each%20other%20inside%20the%20cell.%20And%20then%20filter%2C%20exatly%20as%20your%20%22Recipe%20Example%22%20file%20does.%20Does%20such%20function%20exist%3F%3C%2FP%3E%3CP%3EThanks%20again%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-722093%22%20slang%3D%22en-US%22%3ERe%3A%20Searching%20for%20text%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-722093%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F347933%22%20target%3D%22_blank%22%3E%40Berndvbatanker%3C%2FA%3E%26nbsp%3BHi%20Bernd%2C%20thanks%20for%20your%20answer.%20Seems%20pretty%20interesting%20your%20code%2C%20but%20i%20know%20absolutely%20nothing%20related%20to%20algorithm%20in%20general.%20I%20dont%20even%20know%26nbsp%3B%20where%20should%20I%20start%20using%20that.%20Sorry%3C%2FP%3E%3C%2FLINGO-BODY%3E
ArthurADs
New Contributor

I'm trying to create a function of the following thing:

Search on the sheet "2", in a column "B" (where exist a bunch of cells full of text) a cell that contains info from 2 cells from sheet "1" in columns "A" and "B". For example: On sheet "1" a have 1 cell with "Apple" and the second cell with "Pear", and i need to find on sheet "2" column "B", a recipe that contains "Apple" and "Pear" (those words coming from the two cells from sheet 1), even if those two words are separated inside the cell on sheet "B".  Then create a drop down with the results of the search previously made. 

I'm attaching 2 files with this example to make it easier to understand the idea. 

4 Replies

@ArthurADs 

Hi

Your request is simple , however you have multiple issues with the setup:

1- These are not two "Sheets", these are 2 separate Files "Workbooks". which is NOT an ideal option. Better have the source data (recipes), Your Conditions(Apple, Pear,...) and the final result used for creating drop lists into one single Excel file.

2- The data where we search would better be split into 2 columns say: Recipe name & Recipe details

 

Once you have a much better setup, tens or hundreds of recipes, and assuming that you will always search using 2 conditions (not necessary Apple & Pear) then the steps are as follows:

1- Create a search function that searches for the keywords

2- Create an Advanced Filter (Data Tab >> Advanced)

3- Run the filter automatically every time the search term changes

 

I am attaching a sample file with different data where we want to extract records based on 2 conditions selected from 2 drop lists 'region" & "Sales Rep"

this is exactly what you need. Test by changing the Region or Sales Rep from their drop lists

Note : the source list (like your Recipes) is in columns A:F
The conditions (drop lists) are in Cells H2 & I2
The extracted records are in columns K to P

 

let me help you with an action Plan:
Try to create a list of Recipes more organized and split the data into columns, Having Headers such as: recipe code, Recipe Name, Ingredients, How to prepare...etc

Create 2 lists with the different ingredients you will look for.
i can then help you create the functionality.

a friendly advice, do not use Excel with the same approach we use a word editor. break the data so that Excel can help you extract records.

Good Luck

Nabil Mourad

 

 

@ArthurADs 

Hi Arthur,

i have managed to get list with recipes, take a loom at the attachment. Is you enter column A or column B the list will be generated automatically. 

 

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lngRow As Long
Dim lngRowMax As Long
Dim strBuf As String

If Target.Column < 3 Then

With Cells(Target.Row, 3).Validation
.Delete
lngRowMax = Sheet2.Range("B" & Sheet2.Rows.Count).End(xlUp).Row
For lngRow = 2 To lngRowMax

If InStr(LCase(Sheet2.Range("B" & lngRow).Value), LCase(Cells(Target.Row, 1).Value)) > 0 And _
InStr(LCase(Sheet2.Range("B" & lngRow).Value), LCase(Cells(Target.Row, 2).Value)) > 0 Then

strBuf = strBuf & Sheet2.Range("B" & lngRow).Value & "-"

End If

Next lngRow

strBuf = Left(strBuf, Len(strBuf) - 1)
strBuf = Replace(strBuf, ";", ".")
strBuf = Replace(strBuf, ".", ".")
strBuf = Replace(strBuf, ",", ".")
strBuf = Replace(strBuf, "-", ",")

.Add Type:=xlValidateList, AlertStyle:=xlValidAlertInformation, Operator:=xlBetween, Formula1:=strBuf

End With

End If

End Sub

 

Best regards 

Bernd

https://vba-tanker.com/

@nabilmourad Hey, thanks for your correction related to the "Sheets", haha, I'm pretty new on excel universe, and thanks for you suggestion. Your file is incredible, but it doesn't solve my problem, unfortunetaly. The problem is, there is already a file with all the data related to the recipes, with the following headers: Recipe Name, Author, Descriptions, Ingredients and finally How to do it (the data that exist on "Sheet 2" attached in my post). Since the data "Apple" and "Pear", are surronded by a bunch of text in a single cell inside the column "How to do it", i would need a function that is able to search in those cells (Column "How to do it") those two words "Apple" and "Pear", even if they are not close to each other inside the cell. And then filter, exatly as your "Recipe Example" file does. Does such function exist?

Thanks again

@Berndvbatanker Hi Bernd, thanks for your answer. Seems pretty interesting your code, but i know absolutely nothing related to algorithm in general. I dont even know  where should I start using that. Sorry

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies