Match data from 2 columns and shift row to align

  • I am trying to match data like this (as an example):
    [TABLE="class: grid, width: 500"]

    [tr]


    [td]

    Suburb 1

    [/td]


    [td]

    Suburb 2

    [/td]


    [td]

    Apples

    [/td]


    [td]

    Oranges

    [/td]


    [td]

    Bananas

    [/td]


    [/tr]


    [tr]


    [td]

    A

    [/td]


    [td]

    F

    [/td]


    [td]

    2

    [/td]


    [td]

    6

    [/td]


    [td]

    7

    [/td]


    [/tr]


    [tr]


    [td]

    C

    [/td]


    [td]

    E

    [/td]


    [td]

    4

    [/td]


    [td]

    3

    [/td]


    [td]

    4

    [/td]


    [/tr]


    [tr]


    [td]

    B

    [/td]


    [td]

    D

    [/td]


    [td]

    5

    [/td]


    [td]

    4

    [/td]


    [td]

    3

    [/td]


    [/tr]


    [tr]


    [td]

    D

    [/td]


    [td]

    C

    [/td]


    [td]

    4

    [/td]


    [td]

    5

    [/td]


    [td]

    7

    [/td]


    [/tr]


    [/TABLE]


    to this, so that the data from apples, oranges and bananas shifts WITH suburb 2 to match up with suburb 1.
    [TABLE="class: grid, width: 500"]

    [tr]


    [td]

    Suburb 1

    [/td]


    [td]

    Suburb 2

    [/td]


    [td]

    Apples

    [/td]


    [td]

    Oranges

    [/td]


    [td]

    Bananas

    [/td]


    [/tr]


    [tr]


    [td]

    A

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    C

    [/td]


    [td]

    C

    [/td]


    [td]

    4

    [/td]


    [td]

    5

    [/td]


    [td]

    7

    [/td]


    [/tr]


    [tr]


    [td]

    B

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    D

    [/td]


    [td]

    D

    [/td]


    [td]

    5

    [/td]


    [td]

    4

    [/td]


    [td]

    3

    [/td]


    [/tr]


    [/TABLE]


    I have attached a spreadsheet. I can't figure out what the VBA code would be.


    In the spreadsheet I want to match Column E with Column B and shift E:O to align with B. This code is matching E with A and moving A, C and D. I need A, C and D to stay where they are and match E with B and move E:O.


    [ATTACH=CONFIG]64325[/ATTACH]

  • Re: Match data from 2 columns and shift row to align


    see if this code helps


  • Re: Match data from 2 columns and shift row to align


    This should do

  • Re: Match data from 2 columns and shift row to align


    pangolins and jindons code work beautifully...


    Just for fun..


    Do all the Suburbs that exist in the "Suburb1" column ALSO exist in the "Suburb2" column?


    If they do.. and that's a big IF.. another way maybe would be:


    * Create a sort string based on the "Suburb1" column like:

    Code
    Function sortVals() As String
     With Sheets("Sheet1").Range("A1").CurrentRegion
       sortVals = Join(Application.Transpose(.Offset(1).Columns(1).Value), ",")
     End With
    End Function


    * Then.. sort your values (not including your "Suburb1" column) by using the sortVals string as your CustomOrder.


    Note: If your answer is No to my first question.. this won't work..

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!