Home

Copy data from 2 sheets to others based on criteria

%3CLINGO-SUB%20id%3D%22lingo-sub-743845%22%20slang%3D%22en-US%22%3ECopy%20data%20from%202%20sheets%20to%20others%20based%20on%20criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-743845%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Team%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20an%20inquiry%20similar%20to%20the%20following%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FExcel%2FCopy-Data-to-Other-Sheets-Columns-Based-on-Criteria%2Ftd-p%2F109266%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FExcel%2FCopy-Data-to-Other-Sheets-Columns-Based-on-Criteria%2Ftd-p%2F109266%3C%2FA%3E%3C%2FP%3E%3CP%3EI%20have%20a%20workbook%20with%205%20worksheets.%201%20for%20each%20of%202%20salespersons%2C%20and%201%20for%20each%20of%203%20locations.%3C%2FP%3E%3CP%3EI'd%20like%20each%20of%20the%20salespeople%20to%20fill%20in%20their%20sheet%20-%20with%20a%20field%20for%20the%20location%2C%20and%20then%20have%20the%20data%20automatically%20populate%20in%20to%20the%20location%20sheets.%3C%2FP%3E%3CP%3EUsing%20the%20Array%20formula%20solution%20I%20have%20it%20going%20from%20one%20salesperson%20to%20the%20three%20locations%20no%20worries%2C%20but%20can't%20get%20it%20to%20go%20from%20the%202%20sales%20people%20to%20three.%3C%2FP%3E%3CP%3EThe%20Array%20formula%20is%20my%20preferred%20solution%20as%20it%20updates%20automatically%20without%20a%20button%20click%20for%20the%20user.%3C%2FP%3E%3CP%3EIt%20seems%20like%20the%20loop%20count%20for%20the%20second%20IF%20is%20starting%20from%20where%20the%20first%20left%20off%20maybe%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-LABS%20id%3D%22lingo-labs-743845%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-746690%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20data%20from%202%20sheets%20to%20others%20based%20on%20criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-746690%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F372480%22%20target%3D%22_blank%22%3E%40caleb911%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20changed%20George%20St.%20cell%20D7%20from%20a%20CSE%20formula%20to%20a%20regular%20formula%20that%20handles%20both%20Jack%20and%20Liam.%20The%20AGGREGATE%20function%20requires%20Excel%202010%20or%20later%2C%20and%20has%20similar%20functionality%20to%20SMALL%20but%20doesn't%20need%20the%20CSE.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENote%20that%20the%20formula%20returns%200%20when%20the%20target%20cell%20is%20blank.%20You%20may%20suppress%20those%20zeros%20in%20columns%20N%3AQ%20by%20using%20a%20Custom%20number%20format%20%23%3B-%23%3B%3B%40.%20I%20don't%20have%20a%20good%20tweak%20for%20your%20conditional%20formatting%20in%20column%26nbsp%3B%20R%20to%20get%20the%20pink%20color%2C%20however.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DIFERROR(%3CBR%20%2F%3EINDEX(Jack!D%247%3AD%2429%2C%3CBR%20%2F%3EAGGREGATE(15%2C6%2C%3CBR%20%2F%3E(ROW(Jack!%24C%247%3A%24C%2429)%20-%20ROW(Jack!%24C%247)%2B1)%2F(Jack!%24C%247%3A%24C%2429%3D%24T%244)%2C%3CBR%20%2F%3EROWS(D%247%3AD7)%3CBR%20%2F%3E)%3CBR%20%2F%3E)%2C%3CBR%20%2F%3EIFERROR(%3CBR%20%2F%3EINDEX(Liam!D%247%3AD%2429%2C%3CBR%20%2F%3EAGGREGATE(15%2C6%2C%3CBR%20%2F%3E(ROW(Liam!%24C%247%3A%24C%2429)%20-%20ROW(Liam!%24C%247)%2B1)%2F(Liam!%24C%247%3A%24C%2429%3D%24T%244)%2C%3CBR%20%2F%3EROWS(D%247%3AD7)%20-%20COUNTIF(Jack!%24C%247%3A%24C%2429%2C%24T%244)%3CBR%20%2F%3E)%3CBR%20%2F%3E)%2C%22%22%3CBR%20%2F%3E)%3CBR%20%2F%3E)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-746707%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20data%20from%202%20sheets%20to%20others%20based%20on%20criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-746707%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F23287%22%20target%3D%22_blank%22%3E%40Brad%20Yundt%3C%2FA%3E%26nbsp%3BOh%20man%20that%20is%20so%20much%20tidier%20than%20what%20I've%20just%20finished%20in%20the%20last%20hour.%3C%2FP%3E%3CP%3EI%20used%20the%20one%20to%20one%20for%202%20tables%20in%20each%20of%20the%20location%20sheets%2C%20then%20stacked%20each%20column%20in%20the%20location%20sheet's%20table%20proper.%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20very%20much%20Brad!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-747062%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20data%20from%202%20sheets%20to%20others%20based%20on%20criteria%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-747062%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F372480%22%20target%3D%22_blank%22%3E%40caleb911%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20honestly%20cannot%20decide%20whether%20to%20be%20deeply%20impressed%20by%20your%20formulae%20and%20their%20layout%20or%20horrified%20at%20the%20choice%20of%20tools%20selected%20for%20the%20job!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20PowerQuery%20all%20that%20is%20required%20is%20to%20append%20the%20input%20tables%20and%20filter%20to%20give%20the%20output%20tables.%26nbsp%3B%20I%20appreciate%20that%20you%20want%20a%20more%20dynamic%20behaviour%20and%20so%20are%20attracted%20to%20tables.%26nbsp%3B%20If%20so%2C%20I%20suspect%20that%20this%20one%20workbook%20by%20itself%20would%20justify%20a%20copy%20of%20Office%20365%20to%20gain%20access%20to%20the%20new%20dynamic%20array%20functionality%20(at%20the%20moment%20only%20'insider'%20versions%20but%20expected%20for%20wider%20release%20any%20time%20now).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20formula%20I%20used%20to%20combine%20your%20salesperson%20data%20was%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CFONT%3E%3D%20CHOOSE(%20s%23%2C%20%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CFONT%3EINDEX(%20Jack%2C%20recordNum%23%2C%20columnNum%23%20)%2C%20%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CFONT%3EINDEX(%20Liam%2C%20recordNum%23%2C%20columnNum%23%20)%20)%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CFONT%3EThis%20table%20has%20named%20sub-ranges%20'combinedBranch'%20and%20'combinedData'%20giving%20the%20final%20formula%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CFONT%3E%3D%20FILTER(%20combinedData%2C%20combinedBranch%3D%22George%20St%22%20)%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CFONT%3Eon%20your%20George%20St%20sheet.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%3EEach%20formula%20occupied%20a%20single%20cell%20but%20they%20spill%20to%20fill%20their%20respective%20table.%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
caleb911
New Contributor

Hi Team,

 

I have an inquiry similar to the following

https://techcommunity.microsoft.com/t5/Excel/Copy-Data-to-Other-Sheets-Columns-Based-on-Criteria/td-...

I have a workbook with 5 worksheets. 1 for each of 2 salespersons, and 1 for each of 3 locations.

I'd like each of the salespeople to fill in their sheet - with a field for the location, and then have the data automatically populate in to the location sheets.

Using the Array formula solution I have it going from one salesperson to the three locations no worries, but can't get it to go from the 2 sales people to three.

The Array formula is my preferred solution as it updates automatically without a button click for the user.

It seems like the loop count for the second IF is starting from where the first left off maybe?

 

 

 

3 Replies

@caleb911 

I changed George St. cell D7 from a CSE formula to a regular formula that handles both Jack and Liam. The AGGREGATE function requires Excel 2010 or later, and has similar functionality to SMALL but doesn't need the CSE.

 

Note that the formula returns 0 when the target cell is blank. You may suppress those zeros in columns N:Q by using a Custom number format #;-#;;@. I don't have a good tweak for your conditional formatting in column  R to get the pink color, however.

 

=IFERROR(
INDEX(Jack!D$7:D$29,
AGGREGATE(15,6,
(ROW(Jack!$C$7:$C$29) - ROW(Jack!$C$7)+1)/(Jack!$C$7:$C$29=$T$4),
ROWS(D$7:D7)
)
),
IFERROR(
INDEX(Liam!D$7:D$29,
AGGREGATE(15,6,
(ROW(Liam!$C$7:$C$29) - ROW(Liam!$C$7)+1)/(Liam!$C$7:$C$29=$T$4),
ROWS(D$7:D7) - COUNTIF(Jack!$C$7:$C$29,$T$4)
)
),""
)
)

@Brad Yundt Oh man that is so much tidier than what I've just finished in the last hour.

I used the one to one for 2 tables in each of the location sheets, then stacked each column in the location sheet's table proper. 

Thanks very much Brad!

@caleb911 

I honestly cannot decide whether to be deeply impressed by your formulae and their layout or horrified at the choice of tools selected for the job!

 

In PowerQuery all that is required is to append the input tables and filter to give the output tables.  I appreciate that you want a more dynamic behaviour and so are attracted to tables.  If so, I suspect that this one workbook by itself would justify a copy of Office 365 to gain access to the new dynamic array functionality (at the moment only 'insider' versions but expected for wider release any time now).

 

The formula I used to combine your salesperson data was 

= CHOOSE( s#,

INDEX( Jack, recordNum#, columnNum# ),

INDEX( Liam, recordNum#, columnNum# ) )

This table has named sub-ranges 'combinedBranch' and 'combinedData' giving the final formula

= FILTER( combinedData, combinedBranch="George St" )

on your George St sheet.

 

Each formula occupied a single cell but they spill to fill their respective table.

 

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