Home

If then formula help

%3CLINGO-SUB%20id%3D%22lingo-sub-824712%22%20slang%3D%22en-US%22%3EIf%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824712%22%20slang%3D%22en-US%22%3E%3CP%3EIm%20trying%20to%20build%20a%20formula%20for%20a%20very%20long%20list%20of%20employees%20in%20my%20company.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAn%20example....%3C%2FP%3E%3CP%3EThe%20list%20of%20their%20names%20are%20on%20the%20column%20H%20and%20I%20want%20a%20new%20column%2C%20Colum%20R%2C%20to%20automatically%20add%20their%20employee%20number%20based%20on%20a%20list%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETheir%20names%20repeat%20very%20often%20in%20column%20H%2C%20so%20every%20time%20their%20name%20is%20added%20in%20column%20H%2C%20there%20should%20automatically%20be%20their%20employee%20number%20in%20the%20same%20row%20in%20column%20R.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-824712%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-824790%22%20slang%3D%22en-US%22%3ERe%3A%20If%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824790%22%20slang%3D%22en-US%22%3E%3CP%3EWithout%20knowing%20about%20the%20layout%20of%20your%20sheets%20and%20data%20its%20hard%20to%20suggest%20a%20pin%20point%20solution%20but%20to%20give%20you%20an%20idea%2C%20you%20may%20try%20something%20like%20this%20and%20tweak%20it%20as%20per%20your%20requirement.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAssuming%20you%20have%20a%20Sheet%20called%20List%20with%20Emp%23%20and%20EmpName%2C%20try%20this%20on%20Data%20sheet...%3C%2FP%3E%3CP%3EIn%20R2%3C%2FP%3E%3CP%3E%3DIFERROR(INDEX(List!A%3AA%2CMATCH(H2%2CList!B%3AB%2C0))%2C%22%22)%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-824805%22%20slang%3D%22en-US%22%3ERe%3A%20If%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824805%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%2C%20let%20me%20be%20more%20specific%20I%20did%20not%20specify%20properly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EColum%20%22H%22%20has%20about%20800%20rows%2C%20but%20only%20about%2020%20different%20names%20of%20employees%20that%20repeat%20often%2C%20some%20more%20than%20others.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EColum%20%22R%22%20has%20nothing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20add%20a%20formula%20to%20colum%20R%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%26nbsp%3B%20if%20%22H4%22%20has%20%22JOHN%22%20then%20%22R4%22%20has%20%222525%22%2C%3C%2FP%3E%3CP%3Eif%20%22H5%22%20has%20%22MARY%22%20then%20%22R5%22%20should%20have%20%225151%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20If%20I%20add%20a%20new%20value%2C%20in%20%22H891%22%20that%20is%20%22JOHN%22%20then%20automatically%20%22R891%22%20Should%20fill%20up%20with%20%222525%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20that%20explains%20it%20better%2C%20thank%20you%20for%20the%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-824836%22%20slang%3D%22en-US%22%3ERe%3A%20If%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824836%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F399041%22%20target%3D%22_blank%22%3E%40ocasiomd%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CHR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F399041%22%20target%3D%22_blank%22%3E%40ocasiomd%3C%2FA%3E%26nbsp%3Bwrote%3A%3CBR%20%2F%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%2C%20let%20me%20be%20more%20specific%20I%20did%20not%20specify%20properly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EColum%20%22H%22%20has%20about%20800%20rows%2C%20but%20only%20about%2020%20different%20names%20of%20employees%20that%20repeat%20often%2C%20some%20more%20than%20others.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EColum%20%22R%22%20has%20nothing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20add%20a%20formula%20to%20colum%20R%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%26nbsp%3B%20if%20%22H4%22%20has%20%22JOHN%22%20then%20%22R4%22%20has%20%222525%22%2C%3C%2FP%3E%3CP%3Eif%20%22H5%22%20has%20%22MARY%22%20then%20%22R5%22%20should%20have%20%225151%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20If%20I%20add%20a%20new%20value%2C%20in%20%22H891%22%20that%20is%20%22JOHN%22%20then%20automatically%20%22R891%22%20Should%20fill%20up%20with%20%222525%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20that%20explains%20it%20better%2C%20thank%20you%20for%20the%20help.%3C%2FP%3E%3CHR%20%2F%3E%3C%2FBLOCKQUOTE%3E%3CP%3EThat's%20not%20how%20you%20should%20do%20this.%20You%20must%20be%20referring%20to%20a%20list%20somewhere%20in%20the%20file%20to%20know%20what%20Emp%23%20is%20to%20be%20populated%20in%20column%20R%20based%20on%20EmpName%20in%20column%20H.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHaving%2020%20nested%20IFs%20in%20the%20formula%20doesn't%20make%20any%20sense.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhy%20not%20upload%20a%20truncated%20version%20of%20your%20file%20after%20removing%20any%20sensitive%20info%20in%20it%20so%20that%20we%20can%20figure%20out%20a%20better%20way%20to%20accomplish%20what%20you%20are%20trying%20to%20achieve%3F%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-824933%22%20slang%3D%22en-US%22%3ERe%3A%20If%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824933%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F399041%22%20target%3D%22_blank%22%3E%40ocasiomd%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20simple%20the%20solution%20is%20depends%20very%20much%20on%20the%20effort%20you%20put%20in%20to%20structuring%20the%20problem.%26nbsp%3B%20Here%2C%20I%20have%20started%20with%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E's%20workbook%20and%20inserted%20some%20arbitrary%20names.%26nbsp%3B%20I%20converted%20the%20lookup%20range%20to%20a%20Table%20'array'%20and%20sorted%20it%20alphabetically%20by%20the%20first%20column%20of%20employee%20name.%3C%2FP%3E%3CP%3EThe%20lookup%20formula%20can%20then%20be%20reduced%20to%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CFONT%3E%3D%20IFERROR(%20LOOKUP(EmpName%2C%20Array%20)%2C%20%22%22%20)%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CFONT%3EBeing%20a%20bisection%20search%20it%20is%20very%20fast%20over%20large%20datasets.%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-825028%22%20slang%3D%22en-US%22%3ERe%3A%20If%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-825028%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F399041%22%20target%3D%22_blank%22%3E%40ocasiomd%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20don't%20want%20to%20see%20a%20lookup%20table%2C%20the%20data%20can%20be%20packaged%20into%20an%20array%20constant%3C%2FP%3E%3CP%3E%3CFONT%3E%3D%20%7B%22Berry%22%2C%22E004%22%3B%22Buckland%22%2C%22E0012%22%3B%22Butler%22%2C%22E0028%22%3B%22Campbell%22%2C%22E005%22%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%20%22Davies%22%2C%22E0013%22%3B%22Duncan%22%2C%22E0018%22%3B%22Ellison%22%2C%22E009%22%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22Gray%22%2C%22E006%22%3B%22Hemmings%22%2C%22E0025%22%3B%22Hodges%22%2C%22E0029%22%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22Ince%22%2C%22E0017%22%3B%22Kelly%22%2C%22E003%22%3B%22Kerr%22%2C%22E0024%22%3B%22King%22%7D%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%3Eand%20the%20formula%20would%20still%20work.%26nbsp%3B%20This%20would%20need%20to%20be%20a%20pretty%20short%20list%20though.%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-825093%22%20slang%3D%22en-US%22%3ERe%3A%20If%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-825093%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%3C%2FP%3E%3CP%3ENested%20If%20sounds%20like%20an%20excellent%20solution%2C%20but%20I%20don't%20know%20how%20to%20do%20it.%20Care%20to%20give%20an%20example%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Elets%20say%3C%2FP%3E%3CP%3Ejohn%20%3D%202525%3C%2FP%3E%3CP%3EGrace%20%3D%203737%3C%2FP%3E%3CP%3EMary%20%3D%209898%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENames%20are%20H%20column%2C%20numbers%20are%20the%20empty%20column%20that%20should%20fill%20automatically.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESorry%20for%20not%20giving%20a%20good%20explanation%2C%20the%20list%20is%20confidential%20I%20cannot%20release%20anything%20at%20all%20about%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-825258%22%20slang%3D%22en-US%22%3ERe%3A%20If%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-825258%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F399041%22%20target%3D%22_blank%22%3E%40ocasiomd%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CHR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F399041%22%20target%3D%22_blank%22%3E%40ocasiomd%3C%2FA%3E%26nbsp%3Bwrote%3A%3CBR%20%2F%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%3C%2FP%3E%3CP%3ENested%20If%20sounds%20like%20an%20excellent%20solution%2C%20but%20I%20don't%20know%20how%20to%20do%20it.%20Care%20to%20give%20an%20example%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Elets%20say%3C%2FP%3E%3CP%3Ejohn%20%3D%202525%3C%2FP%3E%3CP%3EGrace%20%3D%203737%3C%2FP%3E%3CP%3EMary%20%3D%209898%3C%2FP%3E%3CHR%20%2F%3E%3C%2FBLOCKQUOTE%3E%3CP%3EAre%20you%20serious%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EDo%20you%20really%20want%20to%20provide%20a%20hard%20coded%20custom%20list%20of%2020%26nbsp%3B%20names%20and%20their%20corresponding%20numbers%20in%20the%20formula%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20stops%20you%20from%20making%20a%20lookup%20table%20as%20I%20showed%20on%20the%20List%20Tab%20in%20the%20file%20I%20uploaded%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20setup%20a%20lookup%20table%20on%20a%20Sheet%20in%20your%20workbook%2C%20you%20can%20easily%20refer%20that%20list%20in%20the%20formula%20and%20the%20advantage%20is%20you%20can%20tweak%20the%20list%20at%20any%20time%20and%20can%20also%20hide%20that%20tab%20so%20that%20it%20is%20not%20visible%20to%20other%20users.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20you%20can%20have%20the%20following%20formula...%3C%2FP%3E%3CP%3EIn%20H4%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DIF(H4%3D%22%22%2C%22%22%2CIFERROR(INDEX(List!A%3AA%2CMATCH(H4%2CList!B%3AB%2C0))%2C%22%22))%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Eand%20copy%20it%20down%20the%20rows.%3C%2FP%3E%3CP%3EThe%20above%20formula%20will%20return%20a%20blank%20(null%20string)%20in%20the%20formula%20cells%20if%20column%20H%20is%20empty%20or%20the%20name%20in%20column%20H%20is%20not%20found%20in%20the%20lookup%20table.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20that%20make%20sense%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-825319%22%20slang%3D%22en-US%22%3ERe%3A%20If%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-825319%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELike%20you%20I%20have%20grave%20reservations%20about%20hard-coding%20a%2020%20row%20table%20(or%20the%20equivalent%20two%20single%20column%20arrays).%26nbsp%3B%20I%20would%20use%20it%20for%20small%20arrays%20such%20as%20%7B%22distinction%22%3B%22merit%22%3B%22pass%22%3B%22fail%22%7D%20that%20are%20unlikely%20to%20change%20for%20the%20lifetime%20of%20the%20workbook.%26nbsp%3B%20Using%20a%20named%20constant%20means%20that%20there%20is%20one%20point%20of%20maintenance%20despite%20it%20being%20used%20many%20times%2C%20as%20would%20a%20table.%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F399041%22%20target%3D%22_blank%22%3E%40ocasiomd%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20built%20the%20named%20constant%3A%3C%2FP%3E%3COL%3E%3CLI%3EFirst%20place%20the%20names%20into%20a%20range%3B%26nbsp%3B%3C%2FLI%3E%3CLI%3EThen%20name%20the%20range%2C%20'arrayConstant'%20(say).%3C%2FLI%3E%3CLI%3EUsing%20any%20scratch%20space%2C%20type%20the%20formula%20%3CSTRONG%3E%3DarrayConstant%3C%2FSTRONG%3E%3C%2FLI%3E%3CLI%3ESelect%20the%20name%20within%20the%20formula%20bar%20and%20use%20%3CSTRONG%3EF9%3C%2FSTRONG%3Eto%20evaluate%20it.%3C%2FLI%3E%3CLI%3EThis%20gives%20the%20correct%20syntax%20for%20the%20array.%26nbsp%3B%20Copy%20it%20from%20the%20formula%20bar.%3C%2FLI%3E%3CLI%3EOpen%20Name%20Manager%20and%20edit%20the%20Name%20by%20pasting%20the%20array%20to%20the%20'Refers%20to'%20in%20place%20of%20the%20range%20reference.%3C%2FLI%3E%3C%2FOL%3E%3CP%3EThe%20named%20array%20constant%20can%20now%20be%20used%20in%20place%20of%20the%20range%20in%20formulas%20that%20accept%20arrays%20(this%20excludes%20%3CSTRONG%3ESUMIFS%3C%2FSTRONG%3E%2C%20for%20example%2C%20that%20only%20works%20with%20range%20references.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-825333%22%20slang%3D%22en-US%22%3ERe%3A%20If%20then%20formula%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-825333%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20not%20challenging%20your%20solution%20but%20does%20this%20really%20make%20any%20sense%20to%20propose%20this%20solution%20to%20a%20person%20who%20doesn't%20even%20know%20how%20to%20construct%20a%20nested%20IF%20syntax%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
ocasiomd
New Contributor

Im trying to build a formula for a very long list of employees in my company.

 

An example....

The list of their names are on the column H and I want a new column, Colum R, to automatically add their employee number based on a list

 

Their names repeat very often in column H, so every time their name is added in column H, there should automatically be their employee number in the same row in column R.

 

Thanks for the help.

 

9 Replies

Without knowing about the layout of your sheets and data its hard to suggest a pin point solution but to give you an idea, you may try something like this and tweak it as per your requirement.

 

Assuming you have a Sheet called List with Emp# and EmpName, try this on Data sheet...

In R2

=IFERROR(INDEX(List!A:A,MATCH(H2,List!B:B,0)),"")

 

 

@Subodh_Tiwari_sktneer 

 

Thank you, let me be more specific I did not specify properly.

 

Colum "H" has about 800 rows, but only about 20 different names of employees that repeat often, some more than others. 

 

Colum "R" has nothing.

 

I want to add a formula to colum R

 

For example,  if "H4" has "JOHN" then "R4" has "2525",

if "H5" has "MARY" then "R5" should have "5151"

 

So, If I add a new value, in "H891" that is "JOHN" then automatically "R891" Should fill up with "2525"

 

Hope that explains it better, thank you for the help.

@ocasiomd 


@ocasiomd wrote:

@Subodh_Tiwari_sktneer 

 

Thank you, let me be more specific I did not specify properly.

 

Colum "H" has about 800 rows, but only about 20 different names of employees that repeat often, some more than others. 

 

Colum "R" has nothing.

 

I want to add a formula to colum R

 

For example,  if "H4" has "JOHN" then "R4" has "2525",

if "H5" has "MARY" then "R5" should have "5151"

 

So, If I add a new value, in "H891" that is "JOHN" then automatically "R891" Should fill up with "2525"

 

Hope that explains it better, thank you for the help.


That's not how you should do this. You must be referring to a list somewhere in the file to know what Emp# is to be populated in column R based on EmpName in column H.

 

Having 20 nested IFs in the formula doesn't make any sense.

 

Why not upload a truncated version of your file after removing any sensitive info in it so that we can figure out a better way to accomplish what you are trying to achieve?

 

 

 

@ocasiomd 

 

How simple the solution is depends very much on the effort you put in to structuring the problem.  Here, I have started with @Subodh_Tiwari_sktneer's workbook and inserted some arbitrary names.  I converted the lookup range to a Table 'array' and sorted it alphabetically by the first column of employee name.

The lookup formula can then be reduced to

= IFERROR( LOOKUP(EmpName, Array ), "" )

Being a bisection search it is very fast over large datasets.

@ocasiomd 

If you don't want to see a lookup table, the data can be packaged into an array constant

= {"Berry","E004";"Buckland","E0012";"Butler","E0028";"Campbell","E005";

     "Davies","E0013";"Duncan","E0018";"Ellison","E009";

      "Gray","E006";"Hemmings","E0025";"Hodges","E0029";

      "Ince","E0017";"Kelly","E003";"Kerr","E0024";"King"}

 

and the formula would still work.  This would need to be a pretty short list though.

@Peter Bartholomew

@Subodh_Tiwari_sktneer

Nested If sounds like an excellent solution, but I don't know how to do it. Care to give an example?

 

lets say

john = 2525

Grace = 3737

Mary = 9898

 

Names are H column, numbers are the empty column that should fill automatically.

 

Sorry for not giving a good explanation, the list is confidential I cannot release anything at all about it.

@ocasiomd 


@ocasiomd wrote:

@Peter Bartholomew

@Subodh_Tiwari_sktneer

Nested If sounds like an excellent solution, but I don't know how to do it. Care to give an example?

 

lets say

john = 2525

Grace = 3737

Mary = 9898


Are you serious?

Do you really want to provide a hard coded custom list of 20  names and their corresponding numbers in the formula?

 

What stops you from making a lookup table as I showed on the List Tab in the file I uploaded?

 

If you setup a lookup table on a Sheet in your workbook, you can easily refer that list in the formula and the advantage is you can tweak the list at any time and can also hide that tab so that it is not visible to other users.

 

Then you can have the following formula...

In H4

=IF(H4="","",IFERROR(INDEX(List!A:A,MATCH(H4,List!B:B,0)),""))

and copy it down the rows.

The above formula will return a blank (null string) in the formula cells if column H is empty or the name in column H is not found in the lookup table.

 

Does that make sense?

@Subodh_Tiwari_sktneer 

Like you I have grave reservations about hard-coding a 20 row table (or the equivalent two single column arrays).  I would use it for small arrays such as {"distinction";"merit";"pass";"fail"} that are unlikely to change for the lifetime of the workbook.  Using a named constant means that there is one point of maintenance despite it being used many times, as would a table.

@ocasiomd 

To built the named constant:

  1. First place the names into a range; 
  2. Then name the range, 'arrayConstant' (say).
  3. Using any scratch space, type the formula =arrayConstant
  4. Select the name within the formula bar and use F9 to evaluate it.
  5. This gives the correct syntax for the array.  Copy it from the formula bar.
  6. Open Name Manager and edit the Name by pasting the array to the 'Refers to' in place of the range reference.

The named array constant can now be used in place of the range in formulas that accept arrays (this excludes SUMIFS, for example, that only works with range references.

@Peter Bartholomew 

I am not challenging your solution but does this really make any sense to propose this solution to a person who doesn't even know how to construct a nested IF syntax?