+ Reply to Thread
Results 1 to 6 of 6

Extracting specific lines from datasheet

Hybrid View

  1. #1
    Registered User
    Join Date
    02-06-2006
    Posts
    19

    Extracting specific lines from datasheet

    Here's my problem;

    I have a sheet with thousands of lines of data captured, eg:

    A B C
    ABC 1231 4321
    PID M1234 H1234
    OBR 98767 LEVO500
    XYZ 5432 23456

    I want to extract only those lines of data that have certain content in column A, in this case any lines that begin with "PID" or "OBR" I want to capture:

    A B C
    PID M1234 H1234
    OBR 98767 LEVO500


    Furthermore, I'd like to combine these output lines into one line, with or without the content of column A included.

    Ideally, my output based on the above dataset would be:

    M1234 H1234 98765 LEVO500


    Suggestions are very much appreciated!
    Thanks very much!

  2. #2
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Hi

    Your requirement are not to clear. However, this code will loop trough sheet named Original_List looking for PID or OBR and will copy this info to sheet name Sort_List.

    It is always a good practice to attached a sample of your work and sample of what you are expected to have.


    Sub sort_pid()
        'Assuming your data is on sheet named Original_List
        'Assuming the new info will be on a sheet named Sort_List
        Sheets("Original_List").Select
        rowcount = Cells(Cells.Rows.Count, "a").End(xlUp).Row
        For i = 1 To rowcount
            Sheets("Original_List").Select
            Range("a" & i).Select
            valu = ActiveCell.Value
            If valu = "PID" Or valu = "OBR" Then
                ActiveCell.EntireRow.Copy
                Sheets("Sort_List").Select
                rowcount = Cells(Cells.Rows.Count, "a").End(xlUp).Row
                Range("a" & rowcount + 1).Select
                ActiveCell.PasteSpecial (xlPasteAll)
            End If
        Next
    End Sub
    Denis

    Please always attach the sample workbook without sensitive information when asking for help

    To add a module
    Press Alt + F11 (this is the Visual Basic Environment)
    Insert Menu, select Module
    Past code there
    Close Visual Basic Environment (X)

  3. #3
    Registered User
    Join Date
    02-06-2006
    Posts
    19
    Thanks for the advice jetted -- I've attached a file with three sheets; I believe what you've posted will take me from sheet 1 to sheet 2; any suggestions on how to merge the adjacent lines in sheet 2 to create the output in sheet 3?

    I'm a total novice when it comes to visual basic -- all help's appreciated!

    Thanks!
    Attached Files Attached Files
    Last edited by SlipperyPete; 12-19-2006 at 05:53 PM.

  4. #4
    Registered User
    Join Date
    02-06-2006
    Posts
    19
    I tried your code, subbed my file name for the one you provided, but am getting a "Compile error: Invalid Outside Procedure".

  5. #5
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Hi

    Sorry for the delay. You will find attached a spreadsheet, run the macro named sort_pid and it will pull the info. As for the merging, this part is still on clear his the data always in this format

    PID
    OBR
    PID
    OBR
    PID
    OBR.... I do I know which PID goes with OBR, I need a common field between them so it could be associated with.
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Try this for the merging the data

    run macro merge_data

    see attached document
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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