Match and sort different sized data sets

John Caines

Well-known Member
Joined
Aug 28, 2006
Messages
1,155
Office Version
  1. 2019
Platform
  1. Windows
Hello All.
I'm trying to match a column of data to another column of data (IE Sort).
But there's a catch! :)
The data sets are different lengths and I have another column that needs to be sorted/moved at the same time.

Here's an example sheet so it starts to make sense (I hope!) :)
Book1
ABCDEFGHIJ
1original listlist to matchdata with list to matchResult I'm looking for isoriginal listlist to matchdata with list to match
2catfoxgolden browncatcatwhite
3dogcatwhitedogdogblack
4pigsheepfatpig
5elephantelephantbigelephantelephantbig
6birddogblackbird
7sheepsheepsheepfat
8antant
9cowcow
10foxgolden brown
Sheet1


Basically in Column A I have my Original list. So all sorted data needs to be adjusted to match this column. Column A data doesn't move, never needs to be sorted.
Col C is the column that needs to move to match column A data , so these cells line up on the same matching rows as the data in col A
Col D is data LOCKED to column C
So if a cell in column C moves, then the same cell of data that was on the same row as Col D moves with it

So Column G:J is how the data cells should end up
I left COL B blank as I was thinking a formula would need to go in there?
But if its easier to delete COLB and move the formula to a different Column, then no problem.

I hope the above makes sense.
My issue here is,
I've been googling etc for the solution, but I always seem to find solutions where the data sets are the same size, or don't mention more than 1 column to move and sort.
And my Col A might have a few 100 more rows of data than Col C & D etc

Hope someone can help me out here and it all makes sense

Many thanks in advance
I really hope someone can work this 1 out,
Really done my head in this 1 to be honest with you! LOL :-)
Best Regards
John C
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Feel there must be an easier way, but how about
+Fluff v2.xlsm
ABCDEFGH
1original listlist to matchdata with list to matchlist to matchdata with list to match
2catfoxgolden browncatwhite
3dogcatwhitedogblack
4pigsheepfat  
5elephantelephantbigelephantbig
6birddogblack  
7sheepsheepfat
8ant  
9cow  
10foxgolden brown
11  
12  
13 
14
Main
Cell Formulas
RangeFormula
G2:G12G2=IFNA(INDEX($D$2:$D$6,MATCH(F2,$C$2:$C$6,0)),"")
F2:F13F2=IF(A2<>"",IF(ISNA(MATCH(A2,$C$2:$C$6,0)),"",A2),IFERROR(INDEX($C$2:$C$6,AGGREGATE(15,6,(ROW($C$2:$C$6)-ROW($C$2)+1)/(ISNA(MATCH($C$2:$C$6,F$1:F1,0))),1)),""))
 
Upvote 0
Solution
I don't think that there will be an easier way @Fluff. I read the question that the original list should be sorted rather than reproducing it, which I've got a formula for but it's messy and relies on assumptions and potential human error.

If that is what is required then I'll post what I came up with but I'll hold back for now because I think that your method would be preferable by far, even if it not what was originally required.
 
Upvote 0
I've been over this multiple times trying to make it work and this is the most stable method that I can come up with. The named ranges cover the majority of the possible errors that I found, however the formula needs to be filled down far enough to allow for all possible mismatches in between the 2 columns (until the formula returns a blank).

Sorting columns C:E by column E smallest to largest matches the example provided. I've left column B empty to reduce the risk of column A being sorted in error.

Book1 (version 2).xlsm
ABCDE
1original listlist to matchdata with list to matchSort order
2catfoxgolden brown9
3dogcatwhite1
4pigsheepfat6
5elephantelephantbig4
6birddogblack2
7sheep3
8ant5
9cow7
108
11 
Sheet1
Cell Formulas
RangeFormula
E2:E11E2=IFERROR(IFERROR(MATCH(C2,Original,0),IF(C2<>"",MAX(COUNTA(Original),E$1:E1)+1,AGGREGATE(15,6,ROW(Original)/ISNA(MATCH(Original,Match,0)),COUNTBLANK(C$1:C1)+1)-1)),"")
Named Ranges
NameRefers ToCells
Match=Sheet1!$C$2:INDEX(Sheet1!C:C,COUNTA(Sheet1!Original,Sheet1!C:C))E2:E11
Original=Sheet1!$A$2:INDEX(Sheet1!$A:$A,MATCH("zzz",Sheet1!$A:$A))E2:E11
 
Upvote 0
Hi Fluff & jasonb75!
Hope you are both well and safe, trying times for everyone.

Good to hear from you both again, and many thanks for both your replies!
1st Jasonb75, my actual sheet this is for has about 613 rows of data, and I'm sorry, I just can't seem to get your formula's to work on it.
If you wanted to take a look at the sheet I have, I can PM it to you, as I can't share it publicly here, but I'm not asking for me to send you my sheet as a PM jasonb75. Only if you are curious as to why I can't get it to work / why your formula doesn't run correctly on this sheet I have.

To be honest, I didn't realise this would be so much trouble, but looking at both your codes, I can see there's a lot going on here! (Not that I fully understand them!)

As to your code Fluff.
Brilliant! This does exactly like I needed.
I'm going to save this sheet, as I can use this in so many ways, it's really great.
Quite often I have a list of data, and I need to resort / match new columns to this original list, but the new list could be much longer.

As said previously, when I was looking for a solution, every website or video I found,, always points to tables with the same amount of columns/rows of data.
I just couldn't finds anything like what you have managed to achieve.

This is really great,
I ran your code Fluff on a sheet with over 613 rows of data in the original colA
and 515 rows of data in Col C & D

It sorted the data perfectly.
I will definitely be saving this sheet to use many times in the future.

Really grateful to you both for finding the time to take a look and digging up solutions.
Have a great day both of you,

Best regards
A very grateful
John CV
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
To be honest, John, what I came up with was more than a little clunky.

As I mentioned in post 3, Fluff and myself interpreted the question differently so I just went with the alternative theory. In all honesty Fluff's method would be preferable by far, to sort the original data in place would be much better done with vba than formulas, although I have no idea how you would even go about it with the way you wanted it done.

@Fluff, would a dictionary object work for this using row numbers as a key? It's something that I really should try to learn but I keep avoiding it.

One thing that I didn't test my theory with was duplicate entries. Also I had assumed that the data entries were all constants, if they are formula generated with blanks instead of empty cells then that would most likely be throwing the counts that I've used to index the data.

If you can send a link to the file in a PM then I would like to have a look and see why it failed out of curiosity, but as you have a solution that you're happy with it is not essential.
 
Upvote 0
Hi Jason, & Fluff,
many thanks to you both.

Yes Jasonb75, I'll gladly sent a link to my sheet, (It will be a dropbox link) but I'll also create a short screencam (like 1 min) just to explain, so it's clear what I was trying to do.

Again, really glad for your help here, I've just saved this sheet now, so I can use it again!

Best regards all
John C
 
Upvote 0
Hi Jasonb75!
Sorry, but yes, you are right! I've checked the wrong solution!
I've just altered it, Going mad here! LOL

Sorry about that.
Also, as a note, I've just contacted Fluff as he's a moderator I see here, and I don't seem to be able to PM you, so I asked him to contact you if I can send you my sheet.

Glad you spotted my error!
Many thanks again Jasonb75

Best regards
John C
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top