Based on the revised sample, (you were right about the real sheet, I tried to make sense of it- and failed!)
The revised layout, although closer to the real one, is far from formula friendly, but I did find a way.
Formulas assume no duplicate Dept / TB code in any one column of the assembled data (same code in multiple columns is ok).
B16 - Cost Centre.
PHP Code:
=IF( B15 = "" , "" , IFERROR ( INDEX ( $C $ 3 : $K $ 3 , IFERROR (MATCH( B15 , $C $ 3 : $K $ 3 , 0 ), 1 )+(( COUNTIF ( INDEX ( $C $ 5 : $K $ 7 , 0 , IFERROR (MATCH( B15 , $C $ 3 : $K $ 3 , 0 ), 1 )), "<>0" )= COUNTIF ( B $ 15 : B15 , INDEX ( $C $ 3 : $K $ 3 , IFERROR (MATCH( B15 , $C $ 3 : $K $ 3 , 0 ), 1 ))))* 2 )), "" ))
Note that the *2 multiplier assumes a continuous pattern of use 1 column, skip 1 column when searching for the cost centres.
C16- Dept / TB code (This one must be Array confirmed with Shift Ctrl Enter).
PHP Code:
=IF( B16 = "" , "" , INDEX ( $D $ 5 : $L $ 7 , INDEX ( $B $ 5 : $B $ 7 ,MATCH( TRUE ,IF( INDEX ( $C $ 5 : $K $ 7 , 0 ,MATCH( B16 , $C $ 3 : $K $ 3 , 0 ))<> 0 ,( $B $ 5 : $B $ 7 >IF( B16 = B15 ,MATCH( C15 , INDEX ( $D $ 5 : $L $ 7 , 0 ,MATCH( B16 , $C $ 3 : $K $ 3 , 0 )), 0 ), 0 ))), 0 )),MATCH( B16 , $C $ 3 : $K $ 3 , 0 )))
D16 - Amount.
PHP Code:
=IF( B16 = "" , "" , INDEX ( $C $ 5 : $K $ 7 ,MATCH( C16 , INDEX ( $D $ 5 : $L $ 7 , 0 ,MATCH( B16 , $C $ 3 : $K $ 3 , 0 )), 0 ),MATCH( B16 , $C $ 3 : $K $ 3 , 0 )))
Note that in the Dept / TB code formula and the Amount formula, some of the ranges have been offset by one column, this is done to align the TB code with the relevant cost centre, when changing the ranges to match other sheets, the format of the offsets must be preserved for the formula to function correctly.
E16 - Debit flag.
See if you can make sense of that, I need to book myself into Arkham Asylum for a few days after trying to get them working right.
Bookmarks