How to sort groups of numbers in rows to interleaved columns

Copper Contributor

Hi Folks

This has had me wracking my brain for a couple of days, so any suggestions hugely appreciated!

I have a sheet that looks in part like the following there's around 2000 rows, so looking a VBA snippet unless there's a funky sort I've not found :)

1 

1 

2  

3 

3 

4 

4 

and I'm after it looking like

1234

134

1234

 

Thanks in advance!

 

3 Replies

@Adrian Watkins , what's the logic of the grouping? I can't see a pattern just by looking at the example.

@TheAntony thanks for the reply! sorry, it’s repeated groups of up to 1-4 sorted numerically, so they are like 111222333444 but some groups may skip some numbers, so min of one number, max of four and results have to be in numeric order 1234 with no gaps for skipped ones. Full job is combining a series of worksheets that were done by row when they should have been column as source for a mail merge :confounded_face:

@Adrian Watkins 

If your version of Excel supports dynamic arrays, and if I understood the logic correctly, you may add helper column

image.png

with formula

=--CONCAT(UNIQUE(MID(A1,SEQUENCE(1,LEN(A1)),1),1))

and sort by it.