consolidate rows into single row

  • Hi,


    I am fairly new to VBA so please go easy on me. I am looking for a code that will consolidate mutiple rows on data into a single row, then delete the unneeded lines. The data is not always in order so I am thinking I would first need to sort the data, but hoping this can be included in the code. In addition, there may be duplicates in the 1st two columns within the raw data, and it would always be the case that the 1st "TIME IN" corresponds to the 1st "TIME OUT".


    The raw data is being copied/pasted from another workbook, via another macro at a specific time of day, so ideally this would run after that macro (ideally 5:00AM).


    [TABLE="width: 267"]

    [tr]


    [TD="class: xl66, width: 56, bgcolor: #4F81BD"]MO #[/TD]
    [TD="class: xl66, width: 71, bgcolor: #4F81BD"]LOCATION[/TD]
    [TD="class: xl67, width: 114, bgcolor: #4F81BD"]TIME IN[/TD]
    [TD="class: xl67, width: 114, bgcolor: #4F81BD"]TIME OUT[/TD]

    [/tr]


    [tr]


    [TD="class: xl68, bgcolor: transparent, align: right"]1234567[/TD]
    [TD="class: xl68, bgcolor: transparent"]STOCK[/TD]
    [TD="class: xl69, bgcolor: transparent, align: right"]9/5/15 2:26 PM[/TD]
    [TD="class: xl69, bgcolor: transparent"] [/TD]

    [/tr]


    [tr]


    [TD="class: xl68, bgcolor: transparent, align: right"]5555555[/TD]
    [TD="class: xl68, bgcolor: transparent"]CNC[/TD]
    [TD="class: xl69, bgcolor: transparent, align: right"]8/29/15 12:00 AM[/TD]
    [TD="class: xl69, bgcolor: transparent"] [/TD]

    [/tr]


    [tr]


    [TD="class: xl68, bgcolor: transparent, align: right"]2345678[/TD]
    [TD="class: xl68, bgcolor: transparent"]PAINT[/TD]
    [TD="class: xl69, bgcolor: transparent, align: right"]9/5/15 2:27 PM[/TD]
    [TD="class: xl69, bgcolor: transparent"] [/TD]

    [/tr]


    [tr]


    [TD="class: xl68, bgcolor: transparent, align: right"]5555555[/TD]
    [TD="class: xl68, bgcolor: transparent"]CNC[/TD]
    [TD="class: xl69, bgcolor: transparent"] [/TD]
    [TD="class: xl69, bgcolor: transparent, align: right"]9/5/15 12:00 AM[/TD]

    [/tr]


    [tr]


    [TD="class: xl68, bgcolor: transparent, align: right"]1234567[/TD]
    [TD="class: xl68, bgcolor: transparent"]STOCK[/TD]
    [TD="class: xl69, bgcolor: transparent, align: right"]9/5/15 2:47 PM[/TD]
    [TD="class: xl69, bgcolor: transparent"] [/TD]

    [/tr]


    [tr]


    [TD="class: xl68, bgcolor: transparent, align: right"]1234567[/TD]
    [TD="class: xl68, bgcolor: transparent"]STOCK[/TD]
    [TD="class: xl69, bgcolor: transparent"] [/TD]
    [TD="class: xl69, bgcolor: transparent, align: right"]9/9/15 12:00 AM[/TD]

    [/tr]


    [tr]


    [TD="class: xl68, bgcolor: transparent, align: right"]3456789[/TD]
    [TD="class: xl68, bgcolor: transparent"]OFFICE[/TD]
    [TD="class: xl69, bgcolor: transparent, align: right"]9/7/15 12:00 AM[/TD]
    [TD="class: xl69, bgcolor: transparent"] [/TD]

    [/tr]


    [tr]


    [TD="class: xl68, bgcolor: transparent, align: right"]1234567[/TD]
    [TD="class: xl68, bgcolor: transparent"]STOCK[/TD]
    [TD="class: xl69, bgcolor: transparent"] [/TD]
    [TD="class: xl69, bgcolor: transparent, align: right"]9/10/15 12:00 AM[/TD]

    [/tr]


    [tr]


    [TD="class: xl68, bgcolor: transparent, align: right"]2345678[/TD]
    [TD="class: xl68, bgcolor: transparent"]PAINT[/TD]
    [TD="class: xl69, bgcolor: transparent"] [/TD]
    [TD="class: xl69, bgcolor: transparent, align: right"]9/6/15 12:00 AM[/TD]

    [/tr]


    [/TABLE]


    Once the code runs, I would like the data to look like this.


    [TABLE="width: 267"]

    [tr]


    [TD="class: xl65, width: 56, bgcolor: #4F81BD"]MO #[/TD]
    [TD="class: xl65, width: 71, bgcolor: #4F81BD"]LOCATION[/TD]
    [TD="class: xl66, width: 114, bgcolor: #4F81BD"]TIME IN[/TD]
    [TD="class: xl66, width: 114, bgcolor: #4F81BD"]TIME OUT[/TD]

    [/tr]


    [tr]


    [TD="class: xl67, bgcolor: transparent, align: right"]1234567[/TD]
    [TD="class: xl67, bgcolor: transparent"]STOCK[/TD]
    [TD="class: xl68, bgcolor: transparent, align: right"]9/5/15 2:26 PM[/TD]
    [TD="class: xl68, bgcolor: transparent, align: right"]9/9/15 12:00 AM[/TD]

    [/tr]


    [tr]


    [TD="class: xl67, bgcolor: transparent, align: right"]1234567[/TD]
    [TD="class: xl67, bgcolor: transparent"]STOCK[/TD]
    [TD="class: xl68, bgcolor: transparent, align: right"]9/5/15 2:47 PM[/TD]
    [TD="class: xl68, bgcolor: transparent, align: right"]9/10/15 12:00 AM[/TD]

    [/tr]


    [tr]


    [TD="class: xl67, bgcolor: transparent, align: right"]2345678[/TD]
    [TD="class: xl67, bgcolor: transparent"]PAINT[/TD]
    [TD="class: xl68, bgcolor: transparent, align: right"]9/5/15 2:27 PM[/TD]
    [TD="class: xl68, bgcolor: transparent, align: right"]9/6/15 12:00 AM[/TD]

    [/tr]


    [tr]


    [TD="class: xl67, bgcolor: transparent, align: right"]3456789[/TD]
    [TD="class: xl67, bgcolor: transparent"]OFFICE[/TD]
    [TD="class: xl68, bgcolor: transparent, align: right"]9/7/15 12:00 AM[/TD]
    [TD="class: xl68, bgcolor: transparent"] [/TD]

    [/tr]


    [tr]


    [TD="class: xl67, bgcolor: transparent, align: right"]5555555[/TD]
    [TD="class: xl67, bgcolor: transparent"]CNC[/TD]
    [TD="class: xl68, bgcolor: transparent, align: right"]8/29/15 12:00 AM[/TD]
    [TD="class: xl68, bgcolor: transparent, align: right"]9/5/15 12:00 AM[/TD]

    [/tr]


    [/TABLE]


    Appreciate any help on the code for this.

  • Re: consolidate rows into single row


    Can it be assumed that the 'IN' row will always appear before the 'OUT' row? and that there will only be 1 matching pair of MO/Location Scratch that but can assume that an 'IN' will match with the next 'OUT' for that MO/Location


    And how many rows are involved? Couple of hundred, couple of thousand? 10s of thousands?? Only asking as there's an easy, but inefficient, way of doing this that can handle a thousand or so rows fairly quickly.

  • Re: consolidate rows into single row


    HI there,


    Can it be assumed that the 'IN' row will always appear before the 'OUT' row? and that there will only be 1 matching pair of MO/Location Scratch that but can assume that an 'IN' will match with the next 'OUT' for that MO/Location - yes 'IN' will always appear before 'OUT', and yes 'IN' will always match the next 'OUT'

    And how many rows are involved? Couple of hundred, couple of thousand? 10s of thousands?? Only asking as there's an easy, but inefficient, way of doing this that can handle a thousand or so rows fairly quickly. - will be anywhere from 5000 to 10,000 rows



    Thank you for your help!!!

  • Re: consolidate rows into single row


    Assuming Herader from A1

  • Re: consolidate rows into single row


    thank you, when I copy the code, I am receiving an error message - run time error '13, type mismatch, on For ii = 1 To UBound(w, 2)?

  • Re: consolidate rows into single row


    You have Comments in col.C
    Strongly recommend not use procedure name like "sort".
    It's a VBA reserved word.

  • Re: consolidate rows into single row


    this works great!! Thank you and thank you for the advise, I will change the "sort" to something more defined.

  • Re: consolidate rows into single row


    [ATTACH=CONFIG]67118[/ATTACH]


    Jindon,


    The file was working wonderful until this morning, when I received a runtime error message type mismatch (on this line of the code SHOWN BELOW), nothing on the files has changed except added more worksheets and more columns to the same sheet but under seperate columns. The raw data seems to copy and paste fine but when it goes to format i receive the error.


    Code
    For ii = 1 To UBound(w, 2)




    The file is too large to attach, but a picture of the column headings is attached in case you need it.
    COLUMN A-E CONTAIN THE RAW DATA COPIED FROM ANOTHER WORKBOOK
    COLUMN F IS BLANK
    COLUMN G-K SHOULD BE FORMATTED DATA PULLED FROM A-E
    COLUMN L-R ADDITIONAL DATA USING FORMATTED DATA IN G-K




    Appreciate any help!


    Thanks,
    Beth

  • Re: consolidate rows into single row


    sorry, here is the correct link
    <a href=http://www.filedropper.com/locationmo><img src=http://www.filedropper.com/download_button.png width=127 height=145 border=0/></a><br /><div style=font-size:9px;font-family:Arial, Helvetica, sans-serif;width:127px;font-color:#44a854;> <a href=http://www.filedropper.com >file storage online</a></div>

  • Re: consolidate rows into single row


    Change to

  • Re: consolidate rows into single row


    Jindon,


    You have been so helpful, the file is timing put before it finishes running, can you take a look and see if there is something that I can do to speed it up. It seems to lock up when it goes to run the macro MOFormat


    http://www.filedropper.com/locationmo


    <a href=http://www.filedropper.com/locationmo><img src=http://www.filedropper.com/download_button.png width=127 height=145 border=0/></a><br /><div style=font-size:9px;font-family:Arial, Helvetica, sans-serif;width:127px;font-color:#44a854;> <a href=http://www.filedropper.com >file upload</a></div>


    Thanks, Beth

  • Re: consolidate rows into single row


    What is the reason to place blank row in row 1?
    It's not a good practice and also a bad procedure name "sort"....

  • Re: consolidate rows into single row


    Jinson,


    Thank you, no reason for clank row in line 1. I have also changed the procedure to not include "sort" in name. I am receiving an error message. Can you take a look at the file.


    http://www.filedropper.com/locationmo_1


    <a href=http://www.filedropper.com/locationmo_1><img src=http://www.filedropper.com/download_button.png width=127 height=145 border=0/></a><br /><div style=font-size:9px;font-family:Arial, Helvetica, sans-serif;width:127px;font-color:#44a854;> <a href=http://www.filedropper.com >share files free</a></div>

Participate now!

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