Results 1 to 4 of 4

Match data in two columns add rows to line up

This is a discussion on Match data in two columns add rows to line up within the Excel Questions forums, part of the Question Forums category; Happy New Year to all. I have two columns. I need to match the data in the columns and insert ...

  1. #1
    Board Regular
    Join Date
    Jun 2008
    Posts
    145

    Default Match data in two columns add rows to line up

    Happy New Year to all.

    I have two columns. I need to match the data in the columns and insert rows to end up across from each other. I apologize for the format, I can't seem to attach my data correctly. A match function with tell me there is a match between the two columns, but then I need the data to end up in the same row in both columns so I am thinking a macro might be needed.

    Thank you

    Mine Yours
    Cust Nbr Cust Name Amount Cust Nbr Cust Name Amount

    890111 Abc 5 750111 Battle 89
    75000 Ionic 349 890111 Abc 54
    5600011 ionic US 2789 75000 Ionic 762300
    576011 Tesa 9872



    Result


    890111 Abc 5

    750111 Abott 89
    890111 Battle 54
    75000 Ionic 349 7500 Ionic 762300
    5600011 ionic US 2789
    576011 Tesa 9872

  2. #2
    Board Regular
    Join Date
    Apr 2009
    Location
    Northeast PA, USA
    Posts
    11,767

    Default Re: Match data in two columns add rows to line up

    Kim B,

    Please attach screenshots of your workbook or a sample workbook that accurately portrays your current workbook on one sheet, and what it should look like 'After' on another sheet. This makes it much easier to see exactly what you want to do, as well as shows us whether there is a consistent number of rows between tables and such.

    Here are three possible ways to post small (copyable) screen shots directly in your post:

    Please post a screenshot of your sheet(s), what you have and what you expect to achieve, with Excel Jeanie HTML 4 (contains graphic instructions).
    http://www.excel-jeanie-html.de/html/hlp_schnell_en.php

    or
    http://RichardSchollarís beta HTML M...om of his post

    or
    Borders-Copy-Paste


    Or, you can upload your workbook to www.box.net and provide us with a link to your workbook.
    Have a great day,
    hiker95

    Windows 8.1, Excel 2007

  3. #3
    Board Regular
    Join Date
    Jun 2008
    Posts
    145

    Default Re: Match data in two columns add rows to line up

    Original data

     ABCDEFG
    1 Mine   Yours 
    2Cust NbrCust NameAmount Cust NbrCust NameAmount
    3750111ABC50000 540611AAA3500
    4980511ACON526400 750111ABC354021
    58750111BATTLE4501 980511ACON526400
    6760511CONJO856400 8750111BATTLE65770
    75705111DIEBOLD51236 87065011CONAIR8540
    86570211FORD578500 5705111DIEBOLD56840
    93564011GALAXY853    


    Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4



    And the result should look like this when the formula/macro is applied

    Result

     ABCDEFGH
    1 Mine   Yours  
    2Cust NbrCust NameAmount Cust NbrCust NameAmount 
    3This row was inserted as a result of function   540611AAA3500 
    4750111ABC50000 750111ABC354021 
    5980511ACON526400 980511ACON526400 
    68750111BATTLE4501 8750111BATTLE65770 
    7This row was inserted as a result of function   87065011CONAIR8540 
    8760511CONJO856400 This row was inserted as a result of function   
    95705111DIEBOLD51236 5705111DIEBOLD56840 
    106570211FORD578500     
    113564011GALAXY853     


    Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4

  4. #4
    Board Regular
    Join Date
    Apr 2009
    Location
    Northeast PA, USA
    Posts
    11,767

    Default Re: Match data in two columns add rows to line up

    Kim B,


    Sample raw data in worksheet Sheet1 before the macro:


    Sheet1

     ABCDEFG
    1 Mine   Yours 
    2Cust NbrCust NameAmount Cust NbrCust NameAmount
    3750111ABC50000 540611AAA3500
    4980511ACON526400 750111ABC354021
    58750111BATTLE4501 980511ACON526400
    6760511CONJO856400 8750111BATTLE65770
    75705111DIEBOLD51236 87065011CONAIR8540
    86570211FORD578500 5705111DIEBOLD56840
    93564011GALAXY853    
    10       
    11       
    12       


    Excel tables to the web >> Excel Jeanie HTML 4




    The two groups of data are sorted ascending separately, and then after the macro we have:


    Sheet1

     ABCDEFG
    1 Mine   Yours 
    2Cust NbrCust NameAmount Cust NbrCust NameAmount
    3    540611AAA3500
    4750111ABC50000 750111ABC354021
    5760511CONJO856400    
    6980511ACON526400 980511ACON526400
    73564011GALAXY853    
    85705111DIEBOLD51236 5705111DIEBOLD56840
    96570211FORD578500    
    108750111BATTLE4501 8750111BATTLE65770
    11    87065011CONAIR8540
    12       


    Excel tables to the web >> Excel Jeanie HTML 4




    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


    Code:
    Option Explicit
    Sub AlignCustNbr()
    ' hiker95, 01/10/2011
    ' http://www.mrexcel.com/forum/showthread.php?t=520077
    '
    ' The macro was modified from code by:
    ' Krishnakumar, 12/12/2010
    ' http://www.ozgrid.com/forum/showthread.php?t=148881
    '
    Dim ws As Worksheet
    Dim LR As Long, a As Long
    Dim CustNbr As Range
    Application.ScreenUpdating = False
    Set ws = Worksheets("Sheet1")
    LR = ws.Range("E" & ws.Rows.Count).End(xlUp).Row
    ws.Range("E3:G" & LR).Sort Key1:=ws.Range("E3"), Order1:=xlAscending, Header:=xlNo, _
      OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
    ws.Range("A3:C" & LR).Sort Key1:=ws.Range("A3"), Order1:=xlAscending, Header:=xlNo, _
      OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    Set CustNbr = ws.Range("A2:C" & LR)
    a = 2
    Do While CustNbr.Cells(a, 1) <> ""
      If CustNbr.Cells(a, 1).Offset(, 4) <> "" Then
        If CustNbr.Cells(a, 1) < CustNbr.Cells(a, 1).Offset(, 4) Then
          CustNbr.Cells(a, 1).Offset(, 4).Resize(, 3).Insert -4121
        ElseIf CustNbr.Cells(a, 1) > CustNbr.Cells(a, 1).Offset(, 4) Then
          CustNbr.Cells(a, 1).Resize(, 3).Insert -4121
          LR = LR + 1
          Set CustNbr = ws.Range("A3:C" & LR)
        End If
      End If
      a = a + 1
    Loop
    Application.ScreenUpdating = 1
    End Sub

    Then run the AlignCustNbr macro,
    Have a great day,
    hiker95

    Windows 8.1, Excel 2007

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com