Excel: how to align matching values between two columns and space out the differences











up vote
1
down vote

favorite












I have two columns of data that overlap, looking something like this:



-------------------------
| Aardvarks | Bears |
| Bears | Dogs |
| Cats | Giraffes |
| Giraffes | Hippos |
| Monkeys | Rhinos |
| Rhinos | Zebras |
-------------------------


Is there any way to align matching values between the two columns, whilst adding blank cells where differences exist, so that I get an end result like this:



-------------------------
| Aardvarks | |
| Bears | Bears |
| Cats | |
| | Dogs |
| Giraffes | Giraffes |
| | Hippos |
| Monkeys | |
| Rhinos | Rhinos |
| | Zebras |
-------------------------


I've seen people ask similar questions on here, but all rely on the Column A having some sort of "complete" data and and Column B having incomplete data that needs sorting.



My issue is that both columns have duplicate and unique data (in the above example, Column A doesn't have all the animals).



Is there some way to align and arrange the columns to get this end result I'm looking for?










share|improve this question
























  • Welcome to Super User. What have you tried so far?
    – CharlieRB
    Sep 27 '16 at 19:53










  • Can we assume that both lists have the common words in the same sequence? Can we also assume that the number of needed blank lines isn't necessarily one?
    – fixer1234
    Sep 27 '16 at 21:39










  • You could probably do this with formulas, but the logical solution would be VBA.
    – fixer1234
    Sep 27 '16 at 21:41










  • @fixer1234, yes to both questions.
    – Beej
    Sep 30 '16 at 14:57










  • Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
    – DavidPostill
    Oct 9 '16 at 8:34















up vote
1
down vote

favorite












I have two columns of data that overlap, looking something like this:



-------------------------
| Aardvarks | Bears |
| Bears | Dogs |
| Cats | Giraffes |
| Giraffes | Hippos |
| Monkeys | Rhinos |
| Rhinos | Zebras |
-------------------------


Is there any way to align matching values between the two columns, whilst adding blank cells where differences exist, so that I get an end result like this:



-------------------------
| Aardvarks | |
| Bears | Bears |
| Cats | |
| | Dogs |
| Giraffes | Giraffes |
| | Hippos |
| Monkeys | |
| Rhinos | Rhinos |
| | Zebras |
-------------------------


I've seen people ask similar questions on here, but all rely on the Column A having some sort of "complete" data and and Column B having incomplete data that needs sorting.



My issue is that both columns have duplicate and unique data (in the above example, Column A doesn't have all the animals).



Is there some way to align and arrange the columns to get this end result I'm looking for?










share|improve this question
























  • Welcome to Super User. What have you tried so far?
    – CharlieRB
    Sep 27 '16 at 19:53










  • Can we assume that both lists have the common words in the same sequence? Can we also assume that the number of needed blank lines isn't necessarily one?
    – fixer1234
    Sep 27 '16 at 21:39










  • You could probably do this with formulas, but the logical solution would be VBA.
    – fixer1234
    Sep 27 '16 at 21:41










  • @fixer1234, yes to both questions.
    – Beej
    Sep 30 '16 at 14:57










  • Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
    – DavidPostill
    Oct 9 '16 at 8:34













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have two columns of data that overlap, looking something like this:



-------------------------
| Aardvarks | Bears |
| Bears | Dogs |
| Cats | Giraffes |
| Giraffes | Hippos |
| Monkeys | Rhinos |
| Rhinos | Zebras |
-------------------------


Is there any way to align matching values between the two columns, whilst adding blank cells where differences exist, so that I get an end result like this:



-------------------------
| Aardvarks | |
| Bears | Bears |
| Cats | |
| | Dogs |
| Giraffes | Giraffes |
| | Hippos |
| Monkeys | |
| Rhinos | Rhinos |
| | Zebras |
-------------------------


I've seen people ask similar questions on here, but all rely on the Column A having some sort of "complete" data and and Column B having incomplete data that needs sorting.



My issue is that both columns have duplicate and unique data (in the above example, Column A doesn't have all the animals).



Is there some way to align and arrange the columns to get this end result I'm looking for?










share|improve this question















I have two columns of data that overlap, looking something like this:



-------------------------
| Aardvarks | Bears |
| Bears | Dogs |
| Cats | Giraffes |
| Giraffes | Hippos |
| Monkeys | Rhinos |
| Rhinos | Zebras |
-------------------------


Is there any way to align matching values between the two columns, whilst adding blank cells where differences exist, so that I get an end result like this:



-------------------------
| Aardvarks | |
| Bears | Bears |
| Cats | |
| | Dogs |
| Giraffes | Giraffes |
| | Hippos |
| Monkeys | |
| Rhinos | Rhinos |
| | Zebras |
-------------------------


I've seen people ask similar questions on here, but all rely on the Column A having some sort of "complete" data and and Column B having incomplete data that needs sorting.



My issue is that both columns have duplicate and unique data (in the above example, Column A doesn't have all the animals).



Is there some way to align and arrange the columns to get this end result I'm looking for?







microsoft-excel sorting alignment






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 27 '16 at 17:30









thilina R

2,11541633




2,11541633










asked Sep 27 '16 at 15:39









Beej

26114




26114












  • Welcome to Super User. What have you tried so far?
    – CharlieRB
    Sep 27 '16 at 19:53










  • Can we assume that both lists have the common words in the same sequence? Can we also assume that the number of needed blank lines isn't necessarily one?
    – fixer1234
    Sep 27 '16 at 21:39










  • You could probably do this with formulas, but the logical solution would be VBA.
    – fixer1234
    Sep 27 '16 at 21:41










  • @fixer1234, yes to both questions.
    – Beej
    Sep 30 '16 at 14:57










  • Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
    – DavidPostill
    Oct 9 '16 at 8:34


















  • Welcome to Super User. What have you tried so far?
    – CharlieRB
    Sep 27 '16 at 19:53










  • Can we assume that both lists have the common words in the same sequence? Can we also assume that the number of needed blank lines isn't necessarily one?
    – fixer1234
    Sep 27 '16 at 21:39










  • You could probably do this with formulas, but the logical solution would be VBA.
    – fixer1234
    Sep 27 '16 at 21:41










  • @fixer1234, yes to both questions.
    – Beej
    Sep 30 '16 at 14:57










  • Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
    – DavidPostill
    Oct 9 '16 at 8:34
















Welcome to Super User. What have you tried so far?
– CharlieRB
Sep 27 '16 at 19:53




Welcome to Super User. What have you tried so far?
– CharlieRB
Sep 27 '16 at 19:53












Can we assume that both lists have the common words in the same sequence? Can we also assume that the number of needed blank lines isn't necessarily one?
– fixer1234
Sep 27 '16 at 21:39




Can we assume that both lists have the common words in the same sequence? Can we also assume that the number of needed blank lines isn't necessarily one?
– fixer1234
Sep 27 '16 at 21:39












You could probably do this with formulas, but the logical solution would be VBA.
– fixer1234
Sep 27 '16 at 21:41




You could probably do this with formulas, but the logical solution would be VBA.
– fixer1234
Sep 27 '16 at 21:41












@fixer1234, yes to both questions.
– Beej
Sep 30 '16 at 14:57




@fixer1234, yes to both questions.
– Beej
Sep 30 '16 at 14:57












Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill
Oct 9 '16 at 8:34




Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill
Oct 9 '16 at 8:34










2 Answers
2






active

oldest

votes

















up vote
2
down vote













Sorry to waste people's time, but after doing even more online searching I found a solution to my own problem.



I found this site below that offers a VBA solution to the problem I was facing. The script worked perfectly for what I was hoping to achieve.



http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/text-functions/line-up-matches






share|improve this answer

















  • 1




    Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
    – DavidPostill
    Oct 9 '16 at 8:35


















up vote
0
down vote













The website looks to be down... thankfully I saved the useful VB last year



Option Explicit

Sub LineEmUp()
'Author: Jerry Beaucaire
'Date: 7/5/2010
'Summary: Line up a random number of columns so all matching
' items are on the same rows
Dim LC As Long
Dim Col As Long
Dim LR As Long
Application.ScreenUpdating = False

'Spot last column of data
LC = Cells(1, Columns.Count).End(xlToLeft).Column

'Add new key column to collect unique values
Cells(1, LC + 1) = "Key"
For Col = 1 To LC
Range(Cells(2, Col), Cells(Rows.Count, Col)).SpecialCells(xlConstants).Copy _
Cells(Rows.Count, LC + 1).End(xlUp).Offset(1)
Next Col

Columns(LC + 1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Cells(1, LC + 2), Unique:=True
Columns(LC + 2).Sort Key1:=Cells(2, LC + 2), Order1:=xlAscending, Header:=xlYes

'Fill in new table headers w/formatting
Range("A1", Cells(1, LC)).Copy Cells(1, LC + 3)

'Fill in new table values
LR = Cells(Rows.Count, LC + 2).End(xlUp).Row
With Range(Cells(2, LC + 3), Cells(LR, LC + 2 + LC))
.FormulaR1C1 = "=IF(ISNUMBER(MATCH(RC" & LC + 2 & ",C[-" & LC + 2 _
& "],0)), RC" & LC + 2 & ", """")"
.Value = .Value
End With

'Cleanup/Erase old values
Range("A1", Cells(1, LC + 2)).EntireColumn.Delete xlShiftToLeft
Columns.Autofit
Application.ScreenUpdating = True
End Sub





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1128865%2fexcel-how-to-align-matching-values-between-two-columns-and-space-out-the-differ%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    Sorry to waste people's time, but after doing even more online searching I found a solution to my own problem.



    I found this site below that offers a VBA solution to the problem I was facing. The script worked perfectly for what I was hoping to achieve.



    http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/text-functions/line-up-matches






    share|improve this answer

















    • 1




      Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
      – DavidPostill
      Oct 9 '16 at 8:35















    up vote
    2
    down vote













    Sorry to waste people's time, but after doing even more online searching I found a solution to my own problem.



    I found this site below that offers a VBA solution to the problem I was facing. The script worked perfectly for what I was hoping to achieve.



    http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/text-functions/line-up-matches






    share|improve this answer

















    • 1




      Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
      – DavidPostill
      Oct 9 '16 at 8:35













    up vote
    2
    down vote










    up vote
    2
    down vote









    Sorry to waste people's time, but after doing even more online searching I found a solution to my own problem.



    I found this site below that offers a VBA solution to the problem I was facing. The script worked perfectly for what I was hoping to achieve.



    http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/text-functions/line-up-matches






    share|improve this answer












    Sorry to waste people's time, but after doing even more online searching I found a solution to my own problem.



    I found this site below that offers a VBA solution to the problem I was facing. The script worked perfectly for what I was hoping to achieve.



    http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/text-functions/line-up-matches







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 30 '16 at 14:58









    Beej

    26114




    26114








    • 1




      Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
      – DavidPostill
      Oct 9 '16 at 8:35














    • 1




      Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
      – DavidPostill
      Oct 9 '16 at 8:35








    1




    1




    Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
    – DavidPostill
    Oct 9 '16 at 8:35




    Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
    – DavidPostill
    Oct 9 '16 at 8:35












    up vote
    0
    down vote













    The website looks to be down... thankfully I saved the useful VB last year



    Option Explicit

    Sub LineEmUp()
    'Author: Jerry Beaucaire
    'Date: 7/5/2010
    'Summary: Line up a random number of columns so all matching
    ' items are on the same rows
    Dim LC As Long
    Dim Col As Long
    Dim LR As Long
    Application.ScreenUpdating = False

    'Spot last column of data
    LC = Cells(1, Columns.Count).End(xlToLeft).Column

    'Add new key column to collect unique values
    Cells(1, LC + 1) = "Key"
    For Col = 1 To LC
    Range(Cells(2, Col), Cells(Rows.Count, Col)).SpecialCells(xlConstants).Copy _
    Cells(Rows.Count, LC + 1).End(xlUp).Offset(1)
    Next Col

    Columns(LC + 1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Cells(1, LC + 2), Unique:=True
    Columns(LC + 2).Sort Key1:=Cells(2, LC + 2), Order1:=xlAscending, Header:=xlYes

    'Fill in new table headers w/formatting
    Range("A1", Cells(1, LC)).Copy Cells(1, LC + 3)

    'Fill in new table values
    LR = Cells(Rows.Count, LC + 2).End(xlUp).Row
    With Range(Cells(2, LC + 3), Cells(LR, LC + 2 + LC))
    .FormulaR1C1 = "=IF(ISNUMBER(MATCH(RC" & LC + 2 & ",C[-" & LC + 2 _
    & "],0)), RC" & LC + 2 & ", """")"
    .Value = .Value
    End With

    'Cleanup/Erase old values
    Range("A1", Cells(1, LC + 2)).EntireColumn.Delete xlShiftToLeft
    Columns.Autofit
    Application.ScreenUpdating = True
    End Sub





    share|improve this answer

























      up vote
      0
      down vote













      The website looks to be down... thankfully I saved the useful VB last year



      Option Explicit

      Sub LineEmUp()
      'Author: Jerry Beaucaire
      'Date: 7/5/2010
      'Summary: Line up a random number of columns so all matching
      ' items are on the same rows
      Dim LC As Long
      Dim Col As Long
      Dim LR As Long
      Application.ScreenUpdating = False

      'Spot last column of data
      LC = Cells(1, Columns.Count).End(xlToLeft).Column

      'Add new key column to collect unique values
      Cells(1, LC + 1) = "Key"
      For Col = 1 To LC
      Range(Cells(2, Col), Cells(Rows.Count, Col)).SpecialCells(xlConstants).Copy _
      Cells(Rows.Count, LC + 1).End(xlUp).Offset(1)
      Next Col

      Columns(LC + 1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Cells(1, LC + 2), Unique:=True
      Columns(LC + 2).Sort Key1:=Cells(2, LC + 2), Order1:=xlAscending, Header:=xlYes

      'Fill in new table headers w/formatting
      Range("A1", Cells(1, LC)).Copy Cells(1, LC + 3)

      'Fill in new table values
      LR = Cells(Rows.Count, LC + 2).End(xlUp).Row
      With Range(Cells(2, LC + 3), Cells(LR, LC + 2 + LC))
      .FormulaR1C1 = "=IF(ISNUMBER(MATCH(RC" & LC + 2 & ",C[-" & LC + 2 _
      & "],0)), RC" & LC + 2 & ", """")"
      .Value = .Value
      End With

      'Cleanup/Erase old values
      Range("A1", Cells(1, LC + 2)).EntireColumn.Delete xlShiftToLeft
      Columns.Autofit
      Application.ScreenUpdating = True
      End Sub





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        The website looks to be down... thankfully I saved the useful VB last year



        Option Explicit

        Sub LineEmUp()
        'Author: Jerry Beaucaire
        'Date: 7/5/2010
        'Summary: Line up a random number of columns so all matching
        ' items are on the same rows
        Dim LC As Long
        Dim Col As Long
        Dim LR As Long
        Application.ScreenUpdating = False

        'Spot last column of data
        LC = Cells(1, Columns.Count).End(xlToLeft).Column

        'Add new key column to collect unique values
        Cells(1, LC + 1) = "Key"
        For Col = 1 To LC
        Range(Cells(2, Col), Cells(Rows.Count, Col)).SpecialCells(xlConstants).Copy _
        Cells(Rows.Count, LC + 1).End(xlUp).Offset(1)
        Next Col

        Columns(LC + 1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Cells(1, LC + 2), Unique:=True
        Columns(LC + 2).Sort Key1:=Cells(2, LC + 2), Order1:=xlAscending, Header:=xlYes

        'Fill in new table headers w/formatting
        Range("A1", Cells(1, LC)).Copy Cells(1, LC + 3)

        'Fill in new table values
        LR = Cells(Rows.Count, LC + 2).End(xlUp).Row
        With Range(Cells(2, LC + 3), Cells(LR, LC + 2 + LC))
        .FormulaR1C1 = "=IF(ISNUMBER(MATCH(RC" & LC + 2 & ",C[-" & LC + 2 _
        & "],0)), RC" & LC + 2 & ", """")"
        .Value = .Value
        End With

        'Cleanup/Erase old values
        Range("A1", Cells(1, LC + 2)).EntireColumn.Delete xlShiftToLeft
        Columns.Autofit
        Application.ScreenUpdating = True
        End Sub





        share|improve this answer












        The website looks to be down... thankfully I saved the useful VB last year



        Option Explicit

        Sub LineEmUp()
        'Author: Jerry Beaucaire
        'Date: 7/5/2010
        'Summary: Line up a random number of columns so all matching
        ' items are on the same rows
        Dim LC As Long
        Dim Col As Long
        Dim LR As Long
        Application.ScreenUpdating = False

        'Spot last column of data
        LC = Cells(1, Columns.Count).End(xlToLeft).Column

        'Add new key column to collect unique values
        Cells(1, LC + 1) = "Key"
        For Col = 1 To LC
        Range(Cells(2, Col), Cells(Rows.Count, Col)).SpecialCells(xlConstants).Copy _
        Cells(Rows.Count, LC + 1).End(xlUp).Offset(1)
        Next Col

        Columns(LC + 1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Cells(1, LC + 2), Unique:=True
        Columns(LC + 2).Sort Key1:=Cells(2, LC + 2), Order1:=xlAscending, Header:=xlYes

        'Fill in new table headers w/formatting
        Range("A1", Cells(1, LC)).Copy Cells(1, LC + 3)

        'Fill in new table values
        LR = Cells(Rows.Count, LC + 2).End(xlUp).Row
        With Range(Cells(2, LC + 3), Cells(LR, LC + 2 + LC))
        .FormulaR1C1 = "=IF(ISNUMBER(MATCH(RC" & LC + 2 & ",C[-" & LC + 2 _
        & "],0)), RC" & LC + 2 & ", """")"
        .Value = .Value
        End With

        'Cleanup/Erase old values
        Range("A1", Cells(1, LC + 2)).EntireColumn.Delete xlShiftToLeft
        Columns.Autofit
        Application.ScreenUpdating = True
        End Sub






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 at 15:39









        Ben

        211




        211






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1128865%2fexcel-how-to-align-matching-values-between-two-columns-and-space-out-the-differ%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]