Sorting Multiple Columns to Match/Align with Data in Column A

PSLAV

New Member
Joined
May 16, 2014
Messages
4
Scenario:

- I have Column A filled with roughly 3000 product IDs. (These are the products I want to update)
- I have Column B filled with roughly 45,000 product IDs (These are all of my product IDs, in which the 3000 or so from Column A are in...)
- Columns C - AZ have data that is connected with the product IDs in column B (the product name, description, price, etc)


I need to find a way to sort the data in columns B-AZ to match/align with the product IDs in Column A, while keeping the information connected to the product IDs intact.

Hopefully I would then be able to scroll down to where my Column A ends, and can then delete the rest of the data in B-Z, leaving me with organized, matched data for my 3000 product IDs.


I hope this makes sense and is clear...I have tried VLookup and IF statements, but I DO NOT want just another column that displays if the data is in Column B, (I already know it is) I need all of the information to be sorted according to Column A's matching Column B's product IDs.


Thank you for your help! I desperately need it!

-PSLAV

Edit: Here is an extremely simplified version of what I am trying to accomplish...
Screenshot%202014-05-16%2013.48.03.png


And want it to look like this
Screenshot%202014-05-16%2013.50.13.png
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I gave it a shot, I know you said you tried vlookup's already but I'm still confused why that doesn't solve your problem. This code assumes you have headers and will put the results in columns E and F. Here's what the output is. Still sorta new to vba so I'm sure there's a better way to go about it.

[TABLE="width: 159"]
<tbody>[TR]
[TD][TABLE="width: 159"]
<tbody>[TR]
[TD]1
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]This is with 2
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]This is with 3
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]This is with 4
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]This is with 5
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]This is with 6
[/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD]This is with 7
[/TD]
[/TR]
[TR]
[TD]8
[/TD]
[TD]This is with 8
[/TD]
[/TR]
[TR]
[TD]9
[/TD]
[TD]This is with 9
[/TD]
[/TR]
[TR]
[TD]10
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12
[/TD]
[TD]This is with 12
[/TD]
[/TR]
[TR]
[TD]13
[/TD]
[TD]This is with 13
[/TD]
[/TR]
[TR]
[TD]14
[/TD]
[TD]This is with 14
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

Code:
Sub SortMatch()


Dim LastRow As Integer


LastRow = Range("B:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row


For i = 2 To LastRow
    Range("E" & i) = Range("A" & i)
    Range("F" & i).FormulaR1C1 = "=vlookup(RC1,R2C2:R" & LastRow & "C3,2,False)"
  Next i


Range("F1:F" & LastRow).SpecialCells(xlCellTypeFormulas, xlErrors).Clear


End Sub
 
Upvote 0
I gave it a shot, I know you said you tried vlookup's already but I'm still confused why that doesn't solve your problem. This code assumes you have headers and will put the results in columns E and F. Here's what the output is. Still sorta new to vba so I'm sure there's a better way to go about it.

[TABLE="width: 159"]
<tbody>[TR]
[TD][TABLE="width: 159"]
<tbody>[TR]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]This is with 2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]This is with 3[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]This is with 4[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]This is with 5[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]This is with 6[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]This is with 7[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]This is with 8[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]This is with 9[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]This is with 12[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]This is with 13[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]This is with 14[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

Code:
Sub SortMatch()


Dim LastRow As Integer


LastRow = Range("B:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row


For i = 2 To LastRow
    Range("E" & i) = Range("A" & i)
    Range("F" & i).FormulaR1C1 = "=vlookup(RC1,R2C2:R" & LastRow & "C3,2,False)"
  Next i


Range("F1:F" & LastRow).SpecialCells(xlCellTypeFormulas, xlErrors).Clear


End Sub


Thank you I will absolutely try this and let you know if it works. I appreciate it!

Vlookup's don't solve my problem (I think), because I am not trying to put results in any new column/cells. I am trying to sort/filter Column B (And all data in columns C:AZ that coincides with it) by what I put in Column A.

Like if I could simply select all columns except A, sort by "matching" column B with column A, my problem would be solved.
 
Upvote 0
RadioME...I could not get this code to work for me...Kept coming up with error codes.

Does no one know how to sort a bunch of data to line up with another column? (ie. not alphabetically/A-Z but based on what is in column A?)
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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