VBA Search for Multiple Criteria

%3CLINGO-SUB%20id%3D%22lingo-sub-1564133%22%20slang%3D%22en-US%22%3EVBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564133%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENeed%20assistance%20in%20%3CU%3Eunderstanding%20and%20formulating%20a%20VBA%20code%3C%2FU%3E%26nbsp%3Bfor%20multiple%20criteria%20search.%20I%20currently%20have%20a%20VBA%20Userform%20that%20searches%20for%20individual%20criteria%20and%20once%20I%20enter%20a%20date%20(currently%20Textbox14)%2C%20click%20update%2C%20that%20search%20order%20is%20closed%20and%20is%20removed%20from%20the%20DashBoard%20worksheet.%20I%20also%20have%20Cmd%20Buttons%20of%20Search%2C%20Refresh%2C%20Update%2C%20Close%20on%20the%20Userform.%20Everything%20works%20perfectly.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I%20want%20to%20do%20is%20expand%20the%20search%20for%20two%20criteria%20%3D%26nbsp%3B%3CU%3E%3CSTRONG%3ESearch%3C%2FSTRONG%3E%3C%2FU%3E%26nbsp%3BTextbox1%20(Date%20Completed%2C%20column%2010)%20and%20Textbox%202%20(Vendor%2C%20column%205)%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20search%20will%20display%20the%20orders%20that%20match.%20%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CU%3E%3CSTRONG%3EDisplay%3C%2FSTRONG%3E%3C%2FU%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CU%3E%3CEM%3EOrder%20Number%3C%2FEM%3E%3C%2FU%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETextbox3%3C%2FP%3E%3CP%3ETextbox4%3C%2FP%3E%3CP%3ETextbox5%3C%2FP%3E%3CP%3Eetc.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETried%20searching%20here%20and%20YouTube%20but%20cannot%20find%20any%20tutorials%20for%20this%3C%2FP%3E%3CP%3E.%3C%2FP%3E%3CP%3EThank%20you%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERoy%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1564133%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1564399%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564399%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F674997%22%20target%3D%22_blank%22%3E%40RoyJr%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20it%20is%20working%20for%20one%20criteria%2C%20then%20it%20sounds%20like%20you%20just%20need%20to%20find%20a%20way%20to%20reference%20a%20cell%20on%20the%20same%20row%2C%20but%20different%20column%20(I'm%20assuming%20you%20are%20searching%20a%20worksheet%20or%20structured%20table)%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20that%20is%20the%20case%2C%20then%20you%20might%20look%20at%20the%20Intersect%20function%2C%20which%20will%20return%20the%20intersection%20of%20a%20row%20and%20column%20range%20(the%20vba%20code%20is%20in%20Sheet1%20code%20module).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIntersect(foundCell.entirerow%2C%20Worksheet.Range(%22A%3AA%22))%26nbsp%3B%3C%2FP%3E%3CP%3EIntersect(foundCell.entirerow%2C%20cell.entirecolumn)%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20you%20should%20be%26nbsp%3B%20able%20to%20check%20the%20value%20of%20the%20intersection%20for%20your%20second%20criteria.%20I%20added%20a%20workbook%20with%20an%20example%20of%20one%20way%20you%20can%20search%20a%20worksheet%20range%20and%20also%20match%20criteria%20in%20another%20column.%20If%20it%20doesn't%20help%2C%20then%20you%20may%20need%20to%20add%20some%20more%20details%20regarding%20what%20you're%20trying%20to%20do%20(perhaps%20upload%20a%20workbook%20w%2F%20sample%20data%20if%20it%20is%20not%20sensitive%20information).%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-1566128%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566128%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F675152%22%20target%3D%22_blank%22%3E%40JMB17%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%2C%20I'm%20working%20on%20two%20computers.%20I%20cannot%20see%20the%20attached%20file%20because%20this%20computer%20does%20not%20have%20a%20full%20suite%20of%20Excel%20and%20the%20other%20is%20restricted%20for%20downloads.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20is%20the%20VBA%20code%20I'm%20using%20and%20working%20perfectly.%26nbsp%3BSo%20instead%20of%20section%20CommandBox1%20having%20only%20one%20search%20criteria%2C%20I%20want%20to%20have%20two%20and%20the%20ability%20to%20list%20up%20to%20ten%20orders%20(TextBox%202%2C%203%2C%20etc)%20that%20meet%20that%20criteria.%20Then%20when%20I%20add%20a%20date%20in%20TextBox14%20and%20click%20the%20update%20button%2C%20those%20orders%20are%20updated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPrivate%20Sub%20CommandButton1_Click()%3C%2FP%3E%3CP%3EDim%20Current_Status%20As%20String%3C%2FP%3E%3CP%3ECurrrent_Status%3DTrim(TextBox1.Text)%3C%2FP%3E%3CP%3Elastrow%3DWorksheets(%22Overall%22).Cells(Rows.Count%2C%201).End(x1Up).Row%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20i%20%3D2%20To%20lastrow%3C%2FP%3E%3CP%3EIf%20Worksheets(%22Overall%22).Cells(i%2C%201).Value%3DCurrent_Status%20Then%3C%2FP%3E%3CP%3ETextBox2.Text%3DWorksheets(%22Overall%22).Cells(i%2C%203).Value%3C%2FP%3E%3CP%3ETextBox14.Text%3DWorksheets(%22Overall%22).Cells(i%2C%2011).Value%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20If%3C%2FP%3E%3CP%3ENext%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E-----------------------------------------------------------%3C%2FP%3E%3CP%3EPrivate%20Sub%20CommandButton2_Click()%3C%2FP%3E%3CP%3EDim%20Current_Status%20As%20String%3C%2FP%3E%3CP%3ECurrrent_Status%3DTrim(TextBox1.Text)%3C%2FP%3E%3CP%3Elastrow%3DWorksheets(%22Overall%22).Cells(Rows.Count%2C%201).End(x1Up).Row%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20i%20%3D2%20To%20lastrow%3C%2FP%3E%3CP%3EIf%20Worksheets(%22Overall%22).Cells(i%2C%201).Value%3DCurrent_Status%20Then%3C%2FP%3E%3CP%3EWorksheets(%22Overall%22).Cells(i%2C%203).Value%3DTextBox2.Text%3C%2FP%3E%3CP%3EWorksheets(%22Overall%22).Cells(i%2C%2011).Value%3DTextBox14.Text%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20If%3C%2FP%3E%3CP%3ENext%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESorry%20for%20the%20long%20post%20but%20I%20hope%20it%20provides%20clarity%20to%20what%20I%20want%20to%20do.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERoy%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1566313%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1566313%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F674997%22%20target%3D%22_blank%22%3E%40RoyJr%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20understand%20correctly%2C%20then%20I%20think%20you%20will%20need%20to%20add%20an%20AND%20operator%20to%20your%20if%20statement%20to%20evaluate%20both%20conditions.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%2C%20if%20you%20want%20to%20load%20multiple%20results%20into%20separate%20sets%20of%20text%20boxes%2C%20then%20I%20think%20you%20will%20need%20a%20counter%20variable%20to%20keep%20a%20running%20total%20of%20number%20of%20matches%20and%20then%2C%20based%20on%20that%20running%20total%2C%20load%20your%20next%20match%20in%20the%20next%20set%20of%20text%26nbsp%3B%20boxes%20set%20up%20to%20hold%20the%20results%20(the%20Select%20Case%20statement%20in%20the%20below%20example%20is%20set%20up%20for%20three).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20if%20you%20think%20you%20might%20expand%20the%20number%20of%20matches%20in%20the%20future%2C%20you%20could%20use%20a%20list%20box%20with%20two%20columns%20to%20hold%20the%20matches.%20And%2C%20if%20you%20wanted%20to%2C%20you%20could%20add%20functions%20to%20update%20only%20matches%20you%20select%20from%20the%20listbox%20or%20all%20matches%20at%20once.%20I%20attached%20a%20screen%20shot%20as%20an%20example.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPrivate%20Sub%20CommandButton1_Click()%0A%20%20Dim%20Current_Status%20As%20String%0A%20%20dim%20count%20as%20long%0A%0A%20%20Current_Status%3DTrim(TextBox1.Text)%0A%20%20lastrow%3DWorksheets(%22Overall%22).Cells(Rows.Count%2C%201).End(x1Up).Row%0A%0A%20%20For%20i%20%3D2%20To%20lastrow%0A%20%20%20%20With%20Worksheets(%22Overall%22)%0A%20%20%20%20%20%20If%20.Cells(i%2C%201).Value%3DCurrent_Status%20And%20.Cells(i%2C%202).Value%3DCRITERIA2%20Then%0A%20%20%20%20%20%20%20%20count%20%3D%20count%2B1%0A%0A%20%20%20%20%20%20%20%20Select%20Case%20count%0A%20%20%20%20%20%20%20%20%20%20Case%201%0A%20%20%20%20%20%20%20%20%20%20%20%20TextBox2.Text%20%3D%20.Cells(i%2C%203).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20TextBox14.Text%20%3D%20.Cells(i%2C%2011).Value%0A%20%20%20%20%20%20%20%20%20%20Case%202%0A%20%20%20%20%20%20%20%20%20%20%20%20'%20Second%20set%20of%20textboxes%20here.%0A%20%20%20%20%20%20%20%20%20%20Case%203%0A%20%20%20%20%20%20%20%20%20%20%20%20'%20Third%20Set%20of%20textboxes%20here%2C%20etc.%0A%20%20%20%20%20%20%20%20End%20Select%0A%20%20%20%20%20%20End%20If%0A%20%20%20%20End%20With%0A%20%20Next%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%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-1571755%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1571755%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F675152%22%20target%3D%22_blank%22%3E%40JMB17%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20List%20Box%20looks%20to%20be%20the%20solution%20I'm%20searching%20for.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20will%20attempt%20to%20recreate%20your%20example.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1572046%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1572046%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F674997%22%20target%3D%22_blank%22%3E%40RoyJr%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20it%20will%20help%2C%20here%20is%20the%20workbook%20I%20was%20playing%20with.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1579678%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1579678%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F675152%22%20target%3D%22_blank%22%3E%40JMB17%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESorry%20for%20the%20delay%20in%20responding.%20Things%20are%20hectic.%26nbsp%3BGetting%20close%20to%20finishing%20this%20project%20using%20your%20examples%20and%20code.%20Thanks%20for%20your%20assistance.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20recreated%20the%20Userform%20minus%20the%20graphics%20on%20the%20Search%20and%20Update%20buttons.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20the%20coding%20just%20need%20some%20clarification%3A%20Criteria%201%20%3D%20TextBox1%20(from%20column%206%20of%20Overall%20worksheet).%20Therefore%2C%20in%20TextBox1%20the%20criteria%20will%20be%20Completed%20%2F%20Yes%20or%20Completed%20%2F%20No%20or%20can%20I%20just%20type%20Completed%20with%20a%20wildcard%20in%20the%20code%20to%20recognize%20any%20text%20after%20Completed%3F%20%26nbsp%3BFor%20Criteria%202%20%3D%20Textbox2%20(from%20column%205%20of%20Overall%20worksheet)%20the%20criteria%20will%20be%20a%20vendor%20like%20ABC%2C%20XYZ%2C%20etc.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EClick%20Search%20and%20the%20Results%20will%20populate%20in%20the%20List%20Box%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20only%20need%20one%20TextBox%20in%20Update.%20So%20TextBox3%20is%20the%20date%20(for%20column%2011%20of%20Overall%20worksheet)%20that%20will%20close%20the%20orders%20found%20from%20the%20criteria.%20Adjusted%20the%20UserForm%20for%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20I%20run%20DeBug%2C%20getting%20error%20-%20End%20If%20without%20block%20if%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAgain%2C%20thank%20you%20for%20your%20assistance.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%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-1580130%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1580130%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F674997%22%20target%3D%22_blank%22%3E%40RoyJr%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20could%20add%20a%20wildcard%20option%20for%20Criteria%201.%20One%20way%20would%20be%20to%20add%20a%20checkbox%20to%20enable%20wildcards%2C%20which%20controls%20a%20module%20variable.%20Then%2C%20the%20search%20function%20could%20check%20that%20module%20variable%20value%20and%20either%20match%20the%20text%20exactly%20or%20compare%20the%20text%20using%20the%20Like%20operator.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fvisual-basic%2Flanguage-reference%2Foperators%2Flike-operator%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fvisual-basic%2Flanguage-reference%2Foperators%2Flike-operator%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20made%20the%20change%20to%20the%20example%20workbook%20and%20included%20comments%20where%20I%20made%20changes.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20error%20you%20noted%20appears%20to%20be%20an%20%22If%2FThen%22%20statement%20that%20is%20missing%20an%20%22End%20If.%22%20You'll%20need%20to%20check%20your%20If%2FThen%20blocks%20and%20make%20sure%20there%20is%20a%20matching%20End%20If.%20I'd%20have%20to%20see%20the%20code%20to%20be%20more%20helpful%20than%20that.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1588042%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1588042%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F675152%22%20target%3D%22_blank%22%3E%40JMB17%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOK.%20Still%20having%20issues%20even%20after%20using%20the%20code%20you%20provided%20above.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAttached%20is%20an%20example%20of%20my%20excel%20file.%20Here%20is%20the%20breakdown%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFrom%20Userform2%20on%20Dashboard%2C%20I%20search%20for%20two%20criteria%20in%20TextBox%201%20(from%20Overall%20column%20C%20or%203)%20and%20Textbox2%20(from%20Overall%20column%20D%20or%204).%20Once%20found%20and%20populated%20in%20ListBox%2C%20I%20enter%20a%20Date%20in%20Userform2%20Textbox3.%20Once%20the%20Update%20is%20clicked%2C%20the%20data%20will%20populate%20in%20Overall%20column%20E%20or%205.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26gt%3B%26gt%3B%26gt%3BJust%20for%20info%3A%20The%20Overall%20Column%20C%20will%20change%20(from%20a%20formula%20on%20this%20worksheet)%20so%20this%20data%20will%20not%20be%20found%20again.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20there%20is%20a%20better%20please%20option%2C%20please%20let%20me%20know.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERoy%20%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1588282%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1588282%22%20slang%3D%22en-US%22%3EIs%20it%20possible%20to%20include%20the%20user%20form%20in%20the%20workbook%3F%20I'm%20afraid%20I%20won't%20be%20able%20to%20do%20much%20without%20seeing%20the%20code.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1614754%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1614754%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F674997%22%20target%3D%22_blank%22%3E%40RoyJr%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHey%20Smart%20Guy%2C%3C%2FP%3E%3CP%3EI%20am%20just%20new%20to%20VBA%20learning%20path.%20Some%20how%20i%20could%20able%20to%20create%20one%20user%20form%20with%20one%20textbox%20search%20and%20get%20the%20data%20into%20the%20listbox.%3C%2FP%3E%3CP%3ENow%20i%20have%20one%20English%20word%20power%20excel%20file.%20Where%20there%20will%20be%203%20textbox.%20One%20by%20word%20search%20%2C%20another%20by%20synonyms%20search%20and%20another%20by%20antonyms%20search.%20the%20search%20can%20be%20either%20of%20any%203%20textbox%20and%20the%20result%20can%20be%20display%20in%20listbox%20below%20with%20the%20words%2C%20synonyms%20%2C%20antonyms%20and%20many%20more%20columns%20say%203%20more%20column.%3C%2FP%3E%3CP%3EThe%20user%20form%20will%20will%20search%2C%20add%2C%20delete%2C%20or%20exit%20records.%3C%2FP%3E%3CP%3EHelp%20of%20to%20get%20the%20understanding%20with%20the%20example%20through%20the%20blog%20post%20or%20youtube%20video.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1614786%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Search%20for%20Multiple%20Criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1614786%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F772520%22%20target%3D%22_blank%22%3E%40kumachir%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESmart%20Guy%3F%3F%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20you%20need%20my%20help%3F%20If%20so%2C%20I%20cannot%20help%20you.%20I'm%20still%20trying%20to%20get%20an%20understanding%20of%20VBA%20as%20well.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOr%20do%20you%20have%20a%20VBA%20example%20code%20for%20what%20I%20require%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello,

 

Need assistance in understanding and formulating a VBA code for multiple criteria search. I currently have a VBA Userform that searches for individual criteria and once I enter a date (currently Textbox14), click update, that search order is closed and is removed from the DashBoard worksheet. I also have Cmd Buttons of Search, Refresh, Update, Close on the Userform. Everything works perfectly. 

 

What I want to do is expand the search for two criteria = Search Textbox1 (Date Completed, column 10) and Textbox 2 (Vendor, column 5) 

 

The search will display the orders that match.   

 

Display  

 

Order Number

 

Textbox3

Textbox4

Textbox5

etc.

 

Tried searching here and YouTube but cannot find any tutorials for this

.

Thank you,

 

Roy

 

11 Replies

@RoyJr 

 

Since it is working for one criteria, then it sounds like you just need to find a way to reference a cell on the same row, but different column (I'm assuming you are searching a worksheet or structured table)?

 

If that is the case, then you might look at the Intersect function, which will return the intersection of a row and column range (the vba code is in Sheet1 code module).

 

Intersect(foundCell.entirerow, Worksheet.Range("A:A")) 

Intersect(foundCell.entirerow, cell.entirecolumn) 

 

Then you should be  able to check the value of the intersection for your second criteria. I added a workbook with an example of one way you can search a worksheet range and also match criteria in another column. If it doesn't help, then you may need to add some more details regarding what you're trying to do (perhaps upload a workbook w/ sample data if it is not sensitive information).

 

 

@JMB17 

 

Unfortunately, I'm working on two computers. I cannot see the attached file because this computer does not have a full suite of Excel and the other is restricted for downloads.

 

Below is the VBA code I'm using and working perfectly. So instead of section CommandBox1 having only one search criteria, I want to have two and the ability to list up to ten orders (TextBox 2, 3, etc) that meet that criteria. Then when I add a date in TextBox14 and click the update button, those orders are updated.

 

Private Sub CommandButton1_Click()

Dim Current_Status As String

Currrent_Status=Trim(TextBox1.Text)

lastrow=Worksheets("Overall").Cells(Rows.Count, 1).End(x1Up).Row

 

For i =2 To lastrow

If Worksheets("Overall").Cells(i, 1).Value=Current_Status Then

TextBox2.Text=Worksheets("Overall").Cells(i, 3).Value

TextBox14.Text=Worksheets("Overall").Cells(i, 11).Value

 

End If

Next

 

End Sub

-----------------------------------------------------------

Private Sub CommandButton2_Click()

Dim Current_Status As String

Currrent_Status=Trim(TextBox1.Text)

lastrow=Worksheets("Overall").Cells(Rows.Count, 1).End(x1Up).Row

 

For i =2 To lastrow

If Worksheets("Overall").Cells(i, 1).Value=Current_Status Then

Worksheets("Overall").Cells(i, 3).Value=TextBox2.Text

Worksheets("Overall").Cells(i, 11).Value=TextBox14.Text

 

End If

Next

 

End Sub

 

Sorry for the long post but I hope it provides clarity to what I want to do.

 

Thank you,

 

Roy

 

@RoyJr 

 

If I understand correctly, then I think you will need to add an AND operator to your if statement to evaluate both conditions.

 

But, if you want to load multiple results into separate sets of text boxes, then I think you will need a counter variable to keep a running total of number of matches and then, based on that running total, load your next match in the next set of text  boxes set up to hold the results (the Select Case statement in the below example is set up for three).

 

However, if you think you might expand the number of matches in the future, you could use a list box with two columns to hold the matches. And, if you wanted to, you could add functions to update only matches you select from the listbox or all matches at once. I attached a screen shot as an example.

 

 

 

Private Sub CommandButton1_Click()
  Dim Current_Status As String
  dim count as long

  Current_Status=Trim(TextBox1.Text)
  lastrow=Worksheets("Overall").Cells(Rows.Count, 1).End(x1Up).Row

  For i =2 To lastrow
    With Worksheets("Overall")
      If .Cells(i, 1).Value=Current_Status And .Cells(i, 2).Value=CRITERIA2 Then
        count = count+1

        Select Case count
          Case 1
            TextBox2.Text = .Cells(i, 3).Value
            TextBox14.Text = .Cells(i, 11).Value
          Case 2
            ' Second set of textboxes here.
          Case 3
            ' Third Set of textboxes here, etc.
        End Select
      End If
    End With
  Next
End Sub

 

 

@JMB17 

 

The List Box looks to be the solution I'm searching for.

 

I will attempt to recreate your example.

 

Thank you. 

@RoyJr 

 

If it will help, here is the workbook I was playing with.

@JMB17 

 

Sorry for the delay in responding. Things are hectic. Getting close to finishing this project using your examples and code. Thanks for your assistance. 

 

I have recreated the Userform minus the graphics on the Search and Update buttons.

 

For the coding just need some clarification: Criteria 1 = TextBox1 (from column 6 of Overall worksheet). Therefore, in TextBox1 the criteria will be Completed / Yes or Completed / No or can I just type Completed with a wildcard in the code to recognize any text after Completed?  For Criteria 2 = Textbox2 (from column 5 of Overall worksheet) the criteria will be a vendor like ABC, XYZ, etc. 

 

Click Search and the Results will populate in the List Box?

 

I only need one TextBox in Update. So TextBox3 is the date (for column 11 of Overall worksheet) that will close the orders found from the criteria. Adjusted the UserForm for this.

 

When I run DeBug, getting error - End If without block if

 

Again, thank you for your assistance. 

 

 

 

@RoyJr 

 

You could add a wildcard option for Criteria 1. One way would be to add a checkbox to enable wildcards, which controls a module variable. Then, the search function could check that module variable value and either match the text exactly or compare the text using the Like operator. 

 

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/like-operator

 

I made the change to the example workbook and included comments where I made changes.  

 

The error you noted appears to be an "If/Then" statement that is missing an "End If." You'll need to check your If/Then blocks and make sure there is a matching End If. I'd have to see the code to be more helpful than that.

@JMB17 

 

OK. Still having issues even after using the code you provided above.

 

Attached is an example of my excel file. Here is the breakdown:

 

From Userform2 on Dashboard, I search for two criteria in TextBox 1 (from Overall column C or 3) and Textbox2 (from Overall column D or 4). Once found and populated in ListBox, I enter a Date in Userform2 Textbox3. Once the Update is clicked, the data will populate in Overall column E or 5.

 

>>>Just for info: The Overall Column C will change (from a formula on this worksheet) so this data will not be found again.

 

If there is a better please option, please let me know.

 

Thank you,

 

Roy     

Is it possible to include the user form in the workbook? I'm afraid I won't be able to do much without seeing the code.

@RoyJr 

Hey Smart Guy,

I am just new to VBA learning path. Some how i could able to create one user form with one textbox search and get the data into the listbox.

Now i have one English word power excel file. Where there will be 3 textbox. One by word search , another by synonyms search and another by antonyms search. the search can be either of any 3 textbox and the result can be display in listbox below with the words, synonyms , antonyms and many more columns say 3 more column.

The user form will will search, add, delete, or exit records.

Help of to get the understanding with the example through the blog post or youtube video.

@kumachir 

 

Smart Guy???

 

Do you need my help? If so, I cannot help you. I'm still trying to get an understanding of VBA as well.

 

Or do you have a VBA example code for what I require?