• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

pairing cells vertically based on closest value on two rows

AndyLaic

New Member
Hi all,
I need to makes pairs of cells base on closest value in column B. Column A has increasing numbers 1 to 60 and they need to stay with the cells in column B after the pairing. To explain:
I have 60 cells in B column, each with a number form 7.01 to 9.5 and I need to obtain 30 pairs of cells by matching the closest values in B column - (for example if I have these numbers 7.85, 7.86, 7.95, 7.95, 8.15 and 8.20, then 7.85 should be paired with 7.86, 7.95 with 7.95 and 8.15 with 8.20)

Ideally the cells would be separated into pairs with spaces between pairs, rather than color paired because with 30 pairs the colors will be exhausted. I attach two files - 1st an example of how paring with color would be and the 2nd with spaces between pairs instead of color paring. Notice than in the example when the cell-pairs have spaces between pairs the numbers in column A are sorted to remain next to the numbers in column B as originally.

Is this possible to achieve?
thank you.
Andy
 

Attachments

  • Pairing with color.xlsx
    11.4 KB · Views: 9
  • Pairing with spaces.xlsx
    11.3 KB · Views: 7
Hmm, perhaps this works:

EDIT: I shifted down your values

in [D2] =IFERROR(SMALL($B$2:INDEX($B$2:$B$11,MATCH(999^99,$B$2:$B$11)),ROWS($A$2:A2)*MOD(ROWS($A$2:A2),2))&" - "&SMALL($B$2:INDEX($B$2:$B$11,MATCH(999^99,$B$2:$B$11)),ROWS($A$2:A2)+1),"")
 

Attachments

  • Copy of Pairing.xlsx
    12.8 KB · Views: 5
My approach is to string the values together in ascending order and then pull them apart in pairs. The tricky part was to generate the number sequence
{1;2; ;3;4; ;5;6; ;...}. The formula I used for that was
= IF( MOD( ℓ, 3), ℓ - QUOTIENT( ℓ, 3), 0 )
where ℓ is the line number. With that done, the formula is no more than
= IF( k, SMALL( list, k ), "" )
As usual, the intended solution is built from array formulas by default.
 

Attachments

  • Pairing with spaces (PB).xlsx
    12.1 KB · Views: 4
Last edited:
Hi, to all!

Another option could be:
=IF(ROWS(D$3:D3)>COUNT(tList)*1.5,"",IF(MOD(ROWS(D$3:D3),3),SMALL(tList,1+COUNT(D$2:D2)),""))

being tList the "entry list". Check file. Blessings!
 

Attachments

  • Paired List with Spaces.xlsx
    10.8 KB · Views: 7
Back
Top