+ Reply to Thread
Results 1 to 12 of 12

Match values from two different columns and sort according to the matched values

  1. #1
    Registered User
    Join Date
    12-16-2013
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2007
    Posts
    10

    Match values from two different columns and sort according to the matched values

    Hi everyone,

    I am Kong from Malaysia. I would like to ask, if I have the following data:

    Column A Column B
    1111 0
    1112 0
    1113 1111
    1114 1112
    1115 1111
    1116 1118

    How do I sort the data so that if the value of Column B is identical with a value in Column A, it will appear below the row of the identical number in Column A. For example: (If value in column B is "1111", its row appears below the row in which "1111" appears in Column A)

    Column A Column B
    1111 0
    1113 1111
    1115 1111

    1112 0
    1114 1112
    1116 1118

    Appreciate everyone who could help.

    With thanks,
    Kong - Malaysia

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Match values from two different columns and sort according to the matched values

    Just select both Column-A & Column-B data and apply the sorting


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    12-16-2013
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Match values from two different columns and sort according to the matched values

    Hi Sixthsense,

    Thank you for your response on my inquiry. If I were to "sort" both columns, it will only appear in a certain order. But I wanted the matched value in Column B to be right below the identical number in Column A. Perhaps the attachment below may help in your understanding of my predicament.

    Anyhow, thanks a lot for your initial explanation!

    Cheers
    Kong
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Match values from two different columns and sort according to the matched values

    No idea how to do it as a formula but I think this macro does it:
    Please Login or Register  to view this content.

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Match values from two different columns and sort according to the matched values

    A formula option: add this to a helper column (e.g. Column C) and sort on this column:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  6. #6
    Registered User
    Join Date
    12-16-2013
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Match values from two different columns and sort according to the matched values

    Dear Yudlugar,

    Appreciate your response on this matter with a macro. May I ask what does this line of code means:

    For count1 = count + 2 To Range("A" & Rows.count).End(xlUp).Row

    What does "&" means in the () of Range function?

    Thanks if you can clarify it to help me understand better.

    Cheers
    Kong

    Quote Originally Posted by yudlugar View Post
    No idea how to do it as a formula but I think this macro does it:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-16-2013
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Match values from two different columns and sort according to the matched values

    OllyXLS,

    Thank you for the formula. It works well on my data.

    Cheers
    Kong

    Quote Originally Posted by OllyXLS View Post
    A formula option: add this to a helper column (e.g. Column C) and sort on this column:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Match values from two different columns and sort according to the matched values

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  9. #9
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Match values from two different columns and sort according to the matched values

    The & is the how you tie a string and a variable or property together.

    So rows.count is the number of rows in the spreadsheet
    "A" & rows.count
    would return A65536 for me, because I have 65536 rows in excel.
    The whole line is a way of finding the last used cell in column A.

  10. #10
    Registered User
    Join Date
    12-16-2013
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Match values from two different columns and sort according to the matched values

    Dear Yudlugar,

    I did some editing to the your earlier macro as shown below:

    Please Login or Register  to view this content.
    Basically, what I intended to do is instead of just shifting Column A and Column B in your code, I wanted to make it to shift the entire row. That is why for the range, I included "Z" as value 2 ( Range("a" & count1, "z" & count1).Cut). However, if you have the code in visual basic to shift the entire row,appreciate if you could let me know.

    Secondly, referring to the attached excel, how do I make all the identical numbers in column A to be grouped together? You can see I try to use this code but it still will not work:

    Please Login or Register  to view this content.
    Appreciate your advice on this matter.

    Regards
    Kong
    Attached Files Attached Files
    Last edited by alansidman; 12-20-2013 at 09:44 AM. Reason: Code tags added.

  11. #11
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Match values from two different columns and sort according to the matched values

    I believe you can do:
    Please Login or Register  to view this content.
    although you might need Range("A" & count2+1) instead of rows(Count2+1)...

    Alternatively, you can use .entirerow to return a whole row:
    Please Login or Register  to view this content.

  12. #12
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Match values from two different columns and sort according to the matched values

    @kongfookann

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between
    Please Login or Register  to view this content.
    tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (I have added them for you today. Please read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Summing columns based on matched values
    By Ace_XL in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-13-2013, 11:32 AM
  2. Compare two List and Sort matched values
    By turist in forum Excel General
    Replies: 9
    Last Post: 03-22-2013, 01:47 AM
  3. Replies: 4
    Last Post: 12-04-2012, 04:45 PM
  4. [SOLVED] Match names and sum the 2 values from matched names
    By score in forum Excel General
    Replies: 3
    Last Post: 09-11-2012, 01:12 AM
  5. Replies: 1
    Last Post: 11-09-2005, 03:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1