SOLVED
Home

How to Return Column Data Based on All Populated Cells in Row Range and Match to Other Worksheet

%3CLINGO-SUB%20id%3D%22lingo-sub-210494%22%20slang%3D%22en-US%22%3EHow%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210494%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EHi%20Everyone%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EI%20need%20help%20with%20an%20issue%20I%20can't%20seem%20to%20find%20an%20exact%20answer%20for.%20Basically%2C%20I%20need%20to%20return%20the%20column%20data%20for%20all%20populated%20cells%20with%20the%20letter%20%22X%22%20in%20the%20row.%20Then%20return%20the%20column%20header%20to%20different%20cells%20in%20the%20row.%26nbsp%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EExample%3A%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CDIV%20class%3D%22cms_table%22%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%3EUser%20ID%3C%2FTD%3E%3CTD%3EJob%201%3C%2FTD%3E%3CTD%3EJob%202%3C%2FTD%3E%3CTD%3EJob%203%3C%2FTD%3E%3CTD%3EJob%204%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%201%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%202%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EJonh.Smith%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3EJob%201%3C%2FTD%3E%3CTD%3EJob%204%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EBob.Lang%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EJob%201%3C%2FTD%3E%3CTD%3EJob%202%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FDIV%3E%3CP%3E%3CBR%20%2F%3E%3CSPAN%3EThe%20formula%20will%20be%20applied%20to%20about%20500%20rows%20of%20data%20with%20about%2030%20columns.%20I%20would%20like%20all%20headers%20to%20be%20returned%20if%20it%20has%20an%20x%20in%20the%20column%20for%20each%20row.%20I%20would%20also%20like%20all%20the%20data%20to%20be%20next%20to%20each%20other%20in%20regards%20to%20the%20columns%20(e.g.%20no%20blank%20cells%20between%20output%20data).%20I%20assume%20this%20can%20be%20taken%20care%20of%20with%20one%20or%20two%20formulas%20that%20can%20be%20copied%20to%20the%20other%20cells.%26nbsp%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EIn%20addition%2C%20I%20have%20another%20issue.%20After%20I%20get%20this%20data%2C%20I%20want%20to%20do%20something%20a%20bit%20more%20complex.%20There's%20another%20sheet%20in%20which%20I%20have%20all%20of%20the%20classes%20that%20each%20user%20should%20be%20taking%20based%20on%20what%20their%20job%20is.%20Each%20user%20will%20be%20taking%20multiple%20classes.%20The%20next%20thing%20I%20need%20help%20with%20is%20matching%20the%20user's%20job%20to%20the%20classes%20they%20should%20be%20taking.%20The%20above%20data%20will%20be%20match%20to%20the%20below%20data.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CDIV%20class%3D%22cms_table%22%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EClass%201%3C%2FTD%3E%3CTD%3EClass%202%3C%2FTD%3E%3CTD%3EClass%203%3C%2FTD%3E%3CTD%3EClass%204%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EJob%201%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EJob%202%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EJob%203%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EJob%204%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FDIV%3E%3CP%3E%3CBR%20%2F%3E%3CSPAN%3EThe%20other%20sheet%20contains%20data%20that%20shows%20which%20class%20a%20user%20should%20be%20taking%20denoted%20by%20the%20letter%20%22X%22%20in%20each%20row.%26nbsp%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EThe%20final%20output%20should%20be%20something%20like%20this%3A%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CDIV%20class%3D%22cms_table%22%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%3EUser%20ID%3C%2FTD%3E%3CTD%3EJob%201%3C%2FTD%3E%3CTD%3EJob%202%3C%2FTD%3E%3CTD%3EJob%203%3C%2FTD%3E%3CTD%3EJob%204%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%201%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%202%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%203%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%204%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%205%3C%2FSTRONG%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EJonh.Smith%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3EJob%201%3C%2FTD%3E%3CTD%3EJob%204%3C%2FTD%3E%3CTD%3EClass%202%3C%2FTD%3E%3CTD%3EClass%204%3C%2FTD%3E%3CTD%3EClass%203%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EBob.Lang%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3EX%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EJob%201%3C%2FTD%3E%3CTD%3EJob%202%3C%2FTD%3E%3CTD%3EClass%201%3C%2FTD%3E%3CTD%3EClass%202%3C%2FTD%3E%3CTD%3EClass%203%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FDIV%3E%3CP%3E%3CBR%20%2F%3EAnother%20output%20format%20could%20be%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%3E%3CSTRONG%3EUser%20ID%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%201%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%203%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%204%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%3E%3CSTRONG%3EOutput%205%3C%2FSTRONG%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EJonh.Smith%3C%2FTD%3E%3CTD%3EJob%201%3C%2FTD%3E%3CTD%3EClass%202%3C%2FTD%3E%3CTD%3EClass%204%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FTD%3E%3CTD%3EClass%203%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EJob%204%3C%2FTD%3E%3CTD%3EClass%201%3C%2FTD%3E%3CTD%3EClass%202%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3EBob.Lang%3C%2FTD%3E%3CTD%3EJob%201%3C%2FTD%3E%3CTD%3EClass%202%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FTD%3E%3CTD%3EClass%204%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3EJob%202%3C%2FTD%3E%3CTD%3EClass%201%3C%2FTD%3E%3CTD%3EClass%204%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3ENote%3A%20In%20this%20case%2C%20duplicate%20values%20are%20fine.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CSPAN%3EI%20am%20not%20an%20advanced%20user%20of%20Excel%20so%20any%20help%20is%20greatly%20appreciated.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-210494%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20%26amp%3B%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ERequests%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211766%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211766%22%20slang%3D%22en-US%22%3E%3CP%3EAnother%20option%20would%20be%20to%20take%20your%20data%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20Copy%20%26gt%3B%20PasteSpecial%20%26gt%3B%20Transpose%3C%2FP%3E%0A%3CP%3E2.%20Remove%20Duplicates%20for%20each%20column%20%26gt%3B%20Data%20Tab%20%26gt%3B%20Remove%20Duplicates%3C%2FP%3E%0A%3CP%3E3.%20Copy%20%26gt%3B%20PasteSpecial%20%26gt%3B%20Transpose%20to%20get%20it%20back%20in%20the%20same%20format%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20it's%20possible%20to%20post%20a%20non-sensitive%20file%20of%20what%20you%20are%20currently%20working%20with%20I'm%20happy%20to%20assist.%26nbsp%3B%20It's%20often%20much%20easier%20to%20help%20with%20an%20example.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211744%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211744%22%20slang%3D%22en-US%22%3E%3CP%3EI%20was%20able%20to%20accomplish%20what%20I%20wanted%20by%20moving%20the%20roles%20column%20to%20the%20end%20of%20the%20pivot%20table.%20However%2C%20I%20would%20like%20to%20do%20the%20same%20thing%20but%20keep%20the%20roles%20column%20at%20the%20beginning.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211500%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211500%22%20slang%3D%22en-US%22%3E%3CP%3EOK%2C%20that%20makes%20sense.%20Changing%20the%20number%20of%20preceding%20columns%20worked.%20Now%20I%20know%20why.%20So%20I%20have%20one%20more%20thing%20if%20you%20wouldn't%20mind%20assisting%20me.%20The%20issue%20I%20am%20currently%20having%20is%20there%20are%20many%20duplicate%20classes%20for%20each%20person%20because%20many%20of%20the%20roles%20require%20the%20same%20classes.%20It's%20probably%20complicated%20to%20try%20and%20remove%20the%20duplicate%20classes%20since%20they're%20assigned%20to%20the%20roles.%20Instead%20of%20doing%20this%2C%20is%20there%20a%20way%20to%20just%20remove%20the%20roles%20and%20keep%20the%20classes%20for%20each%20person%20while%20removing%20the%20duplicates%3F%20In%20regards%20to%20presentation%2C%20the%20duplicate%20classes%20make%20hard%20to%20digest.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211495%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211495%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20Anthony-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGlad%20you%20were%20able%20to%20get%20it%20working.%26nbsp%3B%20I%20used%20the%20Column()%20function%20as%20well%20as%20an%20offset%20value%20in%20order%20to%20auto%20increment%20the%20column%20reference%20in%20the%20Vlookup()%20function.%26nbsp%3B%20You%20can%20adjust%20the%20offset%20value%20or%20just%20hard%20code%20it.%26nbsp%3B%20It's%20really%20up%20to%20you.%26nbsp%3B%20The%20Column()%20function%20returns%20the%20number%20of%20the%20Column%20the%20formula%20is%20in.%26nbsp%3B%20So%20for%20example%20if%20the%20formula%20was%20in%20Column%20A%20it%20will%20return%201%2C%20Column%20B%20returns%202%20.....etc.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211473%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211473%22%20slang%3D%22en-US%22%3E%3CP%3EI%20got%20it%20to%20work%20by%20moving%20my%20row%20headers%20to%20the%20end.%20What%20part%20of%20the%20formula%20causes%20this%20discrepancy%3F%3C%2FP%3E%3CP%3EAgain%2C%20thank%20you%20for%20all%20of%20your%20help.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211470%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211470%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%2C%20that%20was%20really%20helpful.%20I%20was%20actually%20working%20on%20organizing%20my%20data%20into%20that%20format%20already.%20For%20some%20reason%2C%20the%20first%20class%20(the%20one%20in%20the%20second%20column)%20wouldn't%20appear%20using%20the%20formula.%20Luckily%2C%20the%20class%20is%20the%20same%20for%20all%20jobs%20so%20I%20just%20copied%20it%20down.%20I'm%20not%20sure%20if%20I%20am%20entering%20the%20range%20incorrectly%2C%20but%20it%20seems%20to%20be%20fine.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211396%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211396%22%20slang%3D%22en-US%22%3E%3CP%3EIt's%20a%20shame%20you%20can't%20use%20Power%20Query%2C%20it's%20ideal%20for%20this%20situation.%26nbsp%3B%20Maybe%20try%20something%20like%20this%20(see%20attached%20file)%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F36982iE2BE70707036C182%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Job_Class.png%22%20title%3D%22Job_Class.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211328%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211328%22%20slang%3D%22en-US%22%3EIn%20order%20to%20replace%20all%20of%20the%20%22X's%22%20with%20column%20headers%2C%20I%20just%20used%20an%20IF%20statement%20and%20deleted%20all%20of%20the%20in%20between%20blank%20cells.%20I%20just%20need%20to%20figure%20out%20how%20to%20assign%20the%20classes%20based%20on%20roles%20using%20a%20formula.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211324%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211324%22%20slang%3D%22en-US%22%3EMy%20job%20currently%20uses%20Microsoft%20Excel%202013%2C%20and%20I%20am%20unable%20to%20install%20the%20Power%20Query%20add-on.%20It%20looks%20as%20though%20I%20will%20not%20be%20able%20to%20do%20this.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211317%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211317%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Sergei%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20much%20for%20the%20help.%20For%20this%20query%2C%20do%20both%20worksheets%20have%20to%20be%20in%20the%20same%20workbook%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211285%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211285%22%20slang%3D%22en-US%22%3E%3CP%3EMatt%2C%20thank%20you.%20I%20believe%20that%20could%20be%20done%20with%20VBA%20and%20even%20with%20formulas%2C%20but%20PQ%20is%26nbsp%3Bnaturally%20for%20tasks%20like%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-211135%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-211135%22%20slang%3D%22en-US%22%3E%3CP%3ESergei-%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGreat%20example%20of%20how%20robust%20Power%20Query%20can%20be%20in%20a%20situation%20like%20the%20below%20described.%26nbsp%3B%20Thanks%20for%20jumping%20in...I%20had%20thought%20of%20a%20few%20different%20ways%20to%20attack%20the%20issue%20using%20VBA%2C%20but%20I%20believe%20this%20to%20be%20a%20much%20simpler%20solution.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210915%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210915%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Anthony%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20could%20be%20done%20by%20Power%20Query.%20Here%20is%20the%20simple%20mockup%20to%20illustrate%20idea%20based%20on%20your%20initial%20pictures%2C%20for%20the%20real%20data%20queries%20will%20be%20bit%20more%20complex.%3C%2FP%3E%0A%3CP%3EHere%20on%20the%20left%20are%20source%20tables%20and%20resulting%20one%20are%20on%20the%20right%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20684px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F36916i640A6DE7EE77294C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFirst%20query%20generates%20list%20of%20roles%20for%20users%2C%20here%20it%20dynamically%20split%20on%20columns%3C%2FP%3E%0A%3CPRE%3Elet%0A%0A%20%20%20%20Source%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22User%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20UnpivotJobs%20%3D%20Table.UnpivotOtherColumns(Source%2C%20%7B%22User%20ID%22%7D%2C%20%22Attribute%22%2C%20%22Value%22)%2C%0A%20%20%20%20RemoveValues%20%3D%20Table.RemoveColumns(UnpivotJobs%2C%7B%22Value%22%7D)%2C%0A%20%20%20%20GroupRows%20%3D%20Table.Group(RemoveValues%2C%20%7B%22User%20ID%22%7D%2C%20%7B%7B%22Role%22%2C%20each%20%5BAttribute%5D%7D%7D)%2C%0A%20%20%20%20MaxInList%20%3D%20Table.AddColumn(GroupRows%2C%20%22ListMax%22%2C%20each%20List.Count(%5BRole%5D))%2C%0A%20%20%20%20ElementNumber%20%3D%20List.Max(MaxInList%5BListMax%5D)%2C%0A%20%20%20%20ListColumns%20%3D%20List.Transform(%7B1..ElementNumber%7D%2C%20each%20%22Role%20%22%20%26amp%3B%20Number.ToText(_))%2C%0A%20%20%20%20ExtractElements%20%3D%20Table.TransformColumns(GroupRows%2C%0A%20%20%20%20%20%20%20%20%7B%22Role%22%2C%20each%20Text.Combine(List.Transform(_%2C%20Text.From)%2C%20%22%2C%22)%2C%20type%20text%7D)%2C%0A%20%20%20%20SplitElements%20%3D%20Table.SplitColumn(ExtractElements%2C%20%22Role%22%2C%0A%20%20%20%20%20%20%20%20Splitter.SplitTextByDelimiter(%22%2C%22%2C%20QuoteStyle.Csv)%2C%20ListColumns)%0A%0Ain%0A%20%20%20%20SplitElements%3C%2FPRE%3E%0A%3CP%3EFor%20the%20second%20table%20we%20first%20create%20connection%20query%20which%20maps%20roles%20on%20lists%20of%20classes%3C%2FP%3E%0A%3CPRE%3Elet%0A%20%20%20%20Source%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22Job%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20UnpivotClasses%20%3D%20Table.UnpivotOtherColumns(Source%2C%20%7B%22Job%22%7D%2C%20%22Attribute%22%2C%20%22Value%22)%2C%0A%20%20%20%20RemoveValue%20%3D%20Table.RemoveColumns(UnpivotClasses%2C%7B%22Value%22%7D)%2C%0A%20%20%20%20GroupRows%20%3D%20Table.Group(RemoveValue%2C%20%7B%22Job%22%7D%2C%20%7B%7B%22Class%22%2C%20each%20%5BAttribute%5D%7D%7D)%0Ain%0A%20%20%20%20GroupRows%3C%2FPRE%3E%0A%3CP%3Eand%20here%20we%20take%20users%20with%20roles%20and%20merge%20with%20that%20query%3C%2FP%3E%0A%3CPRE%3Elet%0A%0A%20%20%20%20Source%20%3D%20Excel.CurrentWorkbook()%7B%5BName%3D%22User%22%5D%7D%5BContent%5D%2C%0A%20%20%20%20UnpivotJobs%20%3D%20Table.UnpivotOtherColumns(Source%2C%20%7B%22User%20ID%22%7D%2C%20%22Job%22%2C%20%22Value%22)%2C%0A%20%20%20%20RemoveValues%20%3D%20Table.RemoveColumns(UnpivotJobs%2C%7B%22Value%22%7D)%2C%0A%20%20%20%20MergeWithClasses%20%3D%20Table.NestedJoin(RemoveValues%2C%7B%22Job%22%7D%2CClassesForRoles%2C%3CBR%20%2F%3E%20%7B%22Job%22%7D%2C%22Classes%22%2CJoinKind.LeftOuter)%2C%0A%20%20%20%20ExpandClasses%20%3D%20Table.ExpandTableColumn(MergeWithClasses%2C%20%22Classes%22%2C%20%7B%22Class%22%7D%2C%20%7B%22Class%22%7D)%2C%0A%20%20%20%20ExtractClasses%20%3D%20Table.TransformColumns(ExpandClasses%2C%20%7B%22Class%22%2C%3CBR%20%2F%3E%20each%20Text.Combine(List.Transform(_%2C%20Text.From)%2C%20%22%2C%20%22)%2C%20type%20text%7D)%2C%0A%20%20%20%20SortUsers%20%3D%20Table.Sort(ExtractClasses%2C%7B%7B%22User%20ID%22%2C%20Order.Descending%7D%2C%3CBR%20%2F%3E%20%7B%22Job%22%2C%20Order.Ascending%7D%7D)%0Ain%0A%20%20%20%20SortUsers%3C%2FPRE%3E%0A%3CP%3EHere%20classes%20are%20as%20lists%2C%20could%20be%20split%20dynamically%20same%20way%20as%20roles%20in%20first%20query.%20Sample%20file%20is%20attached.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210663%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210663%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20title%3D%22Roles%20and%20Courses%20Matrix%22%20href%3D%22http%3A%2F%2Fwww.fiscal.ca.gov%2Ftraining-academy%2Fdocuments%2FSummaryRolesCourseMatrix20171220.xlsx%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.fiscal.ca.gov%2Ftraining-academy%2Fdocuments%2FSummaryRolesCourseMatrix20171220.xlsx%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20the%20document%20from%20which%20I'll%20be%20pulling%20courses%20depending%20on%20a%20user's%20roles.%20However%2C%20I%20will%20not%20be%20using%20all%20of%20these%20roles%20and%20courses.%20Not%20all%20of%20the%20user's%20have%20all%20of%20the%20jobs%20listed.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210662%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210662%22%20slang%3D%22en-US%22%3E%3CP%3EI%20don't%20have%20the%20spreadsheet%20in%20front%20of%20me%20at%20the%20moment%2C%20but%20a%20good%20estimate%20would%20be%20about%2060%20jobs%20and%2045%20classes.%20I%20saw%20a%20similar%20situation%20to%20mine%20before%20and%20the%20gentleman%20who%20answered%20it%20used%20helping%20columns%20to%20solve%20for%20the%20first%20part%20(adding%20the%20jobs%2C%20column%20headers%2C%20to%20the%20row%20in%20consecutive%20cells).%20He%20used%20a%20complex%20index%20function%20to%20search%20if%20a%20cell%20contained%20a%20value%20and%20then%20added%20the%20column%20header%20data%20to%20the%20cell%20where%20the%20function%20was%20written.%20He%20did%20this%20for%20each%20value%20in%20the%20row.%20Unfortunately%2C%20my%20data%20is%20a%20bit%20different%20than%20that%20of%20the%20person%20he%20was%20helping.%20I%20don't%20know%20how%20to%20go%20about%20accomplishing%20the%20second%20part.%20In%20the%20first%20sheet%2C%20it%20has%20a%20user's%20data%20and%20the%20letter%20%22X%22%20to%20denote%20which%20job%20that%20person%20has.%20There%20are%20probably%2060%20or%20so%20columns%20for%20jobs.%20In%20the%20second%20sheet%2C%20the%20jobs%20are%20the%20row%20headers%20and%20the%20classes%20are%20the%20column%20headers.%20There%20are%20probably%20about%2045%20classes.%20Each%20job%20has%20about%205%20classes%20or%20less.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210645%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Return%20Column%20Data%20Based%20on%20All%20Populated%20Cells%20in%20Row%20Range%20and%20Match%20to%20Other%20Worksheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210645%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20your%20example%20I%20can%20see%20that%20there%20are%20two%20jobs%20for%20each%20participant%20as%20well.%26nbsp%3B%20It%20appears%20that%20each%20job%20is%20only%20associated%20with%20two%20classes.%26nbsp%3B%20Is%20this%20realistic%3F%26nbsp%3B%20Or%20do%20you%20have%20a%20more%20precise%20data%20set%20that%20can%20display%20a%20better%20representation%20of%20your%20data.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20example%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20How%20far%20does%20your%20data%20go%20column%20wise%20for%20jobs%3F%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2.%20%3CSPAN%3E%26nbsp%3BHow%20far%20does%20your%20data%20go%20column%20wise%20for%20classes%3F%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E3.%20What%20is%20the%20max%20number%20of%20jobs%3F%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E4.%20What%20is%20the%20max%20number%20of%20classes%20for%20an%20individual%20job%3F%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI've%20spent%20a%20fair%20amount%20of%20time%20on%20issues%20like%20this%20in%20the%20past%20only%20to%20find%20that%20the%20representation%20of%20data%20provided%20by%20the%20end%20user%20was%20not%20accurate%20which%20caused%20further%20questions.%26nbsp%3B%20In%20order%20to%20potentially%20avoid%20this%20issue%20would%20it%20be%20possible%20for%20you%20to%20confirm%20that%20this%20is%20the%20case%20or%20provide%20a%20more%20data.%26nbsp%3B%20There%20may%20be%20a%20formula%20that%20can%20give%20you%20what%20you%20need%20but%20it's%20more%20likely%20that%20the%20only%20way%20to%20have%20a%20simple%20solution%20would%20be%20to%20implement%20some%20kind%20of%20more%20complex%20logic%20using%20VBA%20code.%26nbsp%3B%20I%20believe%20it%20may%20save%20some%20headaches%20for%20yourself%20as%20well%20as%20other%20people%20replying%20to%20your%20inquiry%20if%20you%20could%20please%20provide%20a%20little%20more%20information.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Anthony Smith
Contributor

Hi Everyone,

I need help with an issue I can't seem to find an exact answer for. Basically, I need to return the column data for all populated cells with the letter "X" in the row. Then return the column header to different cells in the row. 

Example:

User IDJob 1Job 2Job 3Job 4Output 1Output 2 
Jonh.SmithX  XJob 1Job 4 
Bob.LangXX  Job 1Job 2 


The formula will be applied to about 500 rows of data with about 30 columns. I would like all headers to be returned if it has an x in the column for each row. I would also like all the data to be next to each other in regards to the columns (e.g. no blank cells between output data). I assume this can be taken care of with one or two formulas that can be copied to the other cells. 

In addition, I have another issue. After I get this data, I want to do something a bit more complex. There's another sheet in which I have all of the classes that each user should be taking based on what their job is. Each user will be taking multiple classes. The next thing I need help with is matching the user's job to the classes they should be taking. The above data will be match to the below data.

 Class 1Class 2Class 3Class 4
Job 1 X X
Job 2X X 
Job 3 XX 
Job 4XXX 


The other sheet contains data that shows which class a user should be taking denoted by the letter "X" in each row. 

The final output should be something like this:

User IDJob 1Job 2Job 3Job 4Output 1Output 2Output 3Output 4Output 5
Jonh.SmithX  XJob 1Job 4Class 2Class 4Class 3
Bob.LangXX  Job 1Job 2Class 1Class 2Class 3


Another output format could be:

 

User IDOutput 1Output 3Output 4Output 5
Jonh.SmithJob 1Class 2Class 4

Class 3
 Job 4Class 1Class 2 
Bob.LangJob 1Class 2

Class 4
 Job 2Class 1Class 4

Note: In this case, duplicate values are fine. 


I am not an advanced user of Excel so any help is greatly appreciated.

16 Replies

In your example I can see that there are two jobs for each participant as well.  It appears that each job is only associated with two classes.  Is this realistic?  Or do you have a more precise data set that can display a better representation of your data.

 

For example:

 

1. How far does your data go column wise for jobs? 

2.  How far does your data go column wise for classes?

3. What is the max number of jobs?

4. What is the max number of classes for an individual job?

 

I've spent a fair amount of time on issues like this in the past only to find that the representation of data provided by the end user was not accurate which caused further questions.  In order to potentially avoid this issue would it be possible for you to confirm that this is the case or provide a more data.  There may be a formula that can give you what you need but it's more likely that the only way to have a simple solution would be to implement some kind of more complex logic using VBA code.  I believe it may save some headaches for yourself as well as other people replying to your inquiry if you could please provide a little more information.

I don't have the spreadsheet in front of me at the moment, but a good estimate would be about 60 jobs and 45 classes. I saw a similar situation to mine before and the gentleman who answered it used helping columns to solve for the first part (adding the jobs, column headers, to the row in consecutive cells). He used a complex index function to search if a cell contained a value and then added the column header data to the cell where the function was written. He did this for each value in the row. Unfortunately, my data is a bit different than that of the person he was helping. I don't know how to go about accomplishing the second part. In the first sheet, it has a user's data and the letter "X" to denote which job that person has. There are probably 60 or so columns for jobs. In the second sheet, the jobs are the row headers and the classes are the column headers. There are probably about 45 classes. Each job has about 5 classes or less. 

http://www.fiscal.ca.gov/training-academy/documents/SummaryRolesCourseMatrix20171220.xlsx

 

This is the document from which I'll be pulling courses depending on a user's roles. However, I will not be using all of these roles and courses. Not all of the user's have all of the jobs listed. 

Solution

Hi Anthony,

 

That could be done by Power Query. Here is the simple mockup to illustrate idea based on your initial pictures, for the real data queries will be bit more complex.

Here on the left are source tables and resulting one are on the right

image.png

First query generates list of roles for users, here it dynamically split on columns

let

    Source = Excel.CurrentWorkbook(){[Name="User"]}[Content],
    UnpivotJobs = Table.UnpivotOtherColumns(Source, {"User ID"}, "Attribute", "Value"),
    RemoveValues = Table.RemoveColumns(UnpivotJobs,{"Value"}),
    GroupRows = Table.Group(RemoveValues, {"User ID"}, {{"Role", each [Attribute]}}),
    MaxInList = Table.AddColumn(GroupRows, "ListMax", each List.Count([Role])),
    ElementNumber = List.Max(MaxInList[ListMax]),
    ListColumns = List.Transform({1..ElementNumber}, each "Role " & Number.ToText(_)),
    ExtractElements = Table.TransformColumns(GroupRows,
        {"Role", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    SplitElements = Table.SplitColumn(ExtractElements, "Role",
        Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), ListColumns)

in
    SplitElements

For the second table we first create connection query which maps roles on lists of classes

let
    Source = Excel.CurrentWorkbook(){[Name="Job"]}[Content],
    UnpivotClasses = Table.UnpivotOtherColumns(Source, {"Job"}, "Attribute", "Value"),
    RemoveValue = Table.RemoveColumns(UnpivotClasses,{"Value"}),
    GroupRows = Table.Group(RemoveValue, {"Job"}, {{"Class", each [Attribute]}})
in
    GroupRows

and here we take users with roles and merge with that query

let

    Source = Excel.CurrentWorkbook(){[Name="User"]}[Content],
    UnpivotJobs = Table.UnpivotOtherColumns(Source, {"User ID"}, "Job", "Value"),
    RemoveValues = Table.RemoveColumns(UnpivotJobs,{"Value"}),
    MergeWithClasses = Table.NestedJoin(RemoveValues,{"Job"},ClassesForRoles,
{"Job"},"Classes",JoinKind.LeftOuter), ExpandClasses = Table.ExpandTableColumn(MergeWithClasses, "Classes", {"Class"}, {"Class"}), ExtractClasses = Table.TransformColumns(ExpandClasses, {"Class",
each Text.Combine(List.Transform(_, Text.From), ", "), type text}), SortUsers = Table.Sort(ExtractClasses,{{"User ID", Order.Descending},
{"Job", Order.Ascending}}) in SortUsers

Here classes are as lists, could be split dynamically same way as roles in first query. Sample file is attached.

Sergei-

 

Great example of how robust Power Query can be in a situation like the below described.  Thanks for jumping in...I had thought of a few different ways to attack the issue using VBA, but I believe this to be a much simpler solution.

Matt, thank you. I believe that could be done with VBA and even with formulas, but PQ is naturally for tasks like this.

Hi Sergei,

 

Thank you so much for the help. For this query, do both worksheets have to be in the same workbook? 

My job currently uses Microsoft Excel 2013, and I am unable to install the Power Query add-on. It looks as though I will not be able to do this.
In order to replace all of the "X's" with column headers, I just used an IF statement and deleted all of the in between blank cells. I just need to figure out how to assign the classes based on roles using a formula.

It's a shame you can't use Power Query, it's ideal for this situation.  Maybe try something like this (see attached file):

Job_Class.png

Thank you, that was really helpful. I was actually working on organizing my data into that format already. For some reason, the first class (the one in the second column) wouldn't appear using the formula. Luckily, the class is the same for all jobs so I just copied it down. I'm not sure if I am entering the range incorrectly, but it seems to be fine.

I got it to work by moving my row headers to the end. What part of the formula causes this discrepancy?

Again, thank you for all of your help. 

Hey Anthony-

 

Glad you were able to get it working.  I used the Column() function as well as an offset value in order to auto increment the column reference in the Vlookup() function.  You can adjust the offset value or just hard code it.  It's really up to you.  The Column() function returns the number of the Column the formula is in.  So for example if the formula was in Column A it will return 1, Column B returns 2 .....etc.

OK, that makes sense. Changing the number of preceding columns worked. Now I know why. So I have one more thing if you wouldn't mind assisting me. The issue I am currently having is there are many duplicate classes for each person because many of the roles require the same classes. It's probably complicated to try and remove the duplicate classes since they're assigned to the roles. Instead of doing this, is there a way to just remove the roles and keep the classes for each person while removing the duplicates? In regards to presentation, the duplicate classes make hard to digest. 

I was able to accomplish what I wanted by moving the roles column to the end of the pivot table. However, I would like to do the same thing but keep the roles column at the beginning. 

Another option would be to take your data:

 

1. Copy > PasteSpecial > Transpose

2. Remove Duplicates for each column > Data Tab > Remove Duplicates

3. Copy > PasteSpecial > Transpose to get it back in the same format

 

If it's possible to post a non-sensitive file of what you are currently working with I'm happy to assist.  It's often much easier to help with an example.

 

Related Conversations
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
*Updated 9/3* Syncing in Microsoft Edge Preview Channels
Elliot Kirk in Articles on
201 Replies
Early preview of Microsoft Edge group policies
Sean Lyndersay in Discussions on
65 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
2 Replies