+ Reply to Thread
Results 1 to 8 of 8

How do I Concatenate these Dynamic Rows

  1. #1
    Registered User
    Join Date
    05-17-2005
    Posts
    8

    Question How do I Concatenate these Dynamic Rows

    I have the following data that I am unable to automatically concatenate because the data is always dynamic. I import this data from a text file and I need to get "For example:" and the rows belonging to "For example:" into one cell in a column called Example.
    Here is the data with four of the varying ranges.

    For example:
    G026: /etc/default/login does not specify 'CONSOLE=/dev/console', '/dev/null', or 'none'.


    For example:
    CRITICAL: Security Patch(es) Not Installed: (16).
    CRITICAL: Recommended Patch(es) Not Installed: (16).
    CRITICAL: Y2K Patch(es) Not Installed: (0).
    CRITICAL: Installed Recommended Patch(es) That Are Outdated: (148).
    OPTIONAL: System Software Patch(es) Not Installed/Outdated: (111).
    cp6 Has (183) Missing/Old Critical Patch(es)
    cp6 Has (111) Missing/Old System Software Patch(es).


    For example:
    -rw-rw-r-- 1 bin bin 5560 Nov 9 1998 /usr/dt/share/man/man1/xmbind.1x


    For example:
    -rw-rw-r-- 1 root bin 11592 Dec 7 1999 /usr/lib/libsx.so.1
    -rwxrwxr-x 1 root bin 3244 Dec 3 1999 /usr/openwin/lib/locale/iso_8859_1/libs/wckind.so.0
    -rwxrwxr-x 1 bin bin 103904 Nov 5 1999 /usr/openwin/lib/xil/utils/xiliUtils.so.2
    -rwxrwxr-x 1 bin bin 20656 Nov 5 1999 /usr/openwin/lib/xil/devhandlers/xilCompute_SUNWkcms.so.2
    -rwxrwxr-x 1 bin bin 69068 Nov 5 1999 /usr/openwin/lib/xil/devhandlers/xilIO_SUNWcg6.so.2
    -rwxrwxr-x 1 bin bin 51972 Nov 5 1999 /usr/openwin/lib/xil/devhandlers/xilIO_SUNWxlib.so.2
    -rwxrwxr-x 1 bin bin 36692 Nov 5 1999 /usr/openwin/lib/xil/devhandlers/xilIO_SUNWxshm.so.2
    -rwxrwxr-x 1 root bin 36452 Dec 7 1999 /usr/openwin/lib/xil/devhandlers/xilIO_SUNWcg14.so.2
    -rwxrwxr-x 1 root bin 1062312 Dec 7 1999 /usr/openwin/lib/xil/devhandlers/xilCompute_VIS.so.2
    -rwxrwxr-x 1 root bin 1168428 Dec 7 1999 /usr/openwin/lib/xil/devhandlers/xilIO_SUNWffb.so.2

  2. #2
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    try this macro - limited at this time to 20 sets of string to concatenate

    Sub Macro1()
    'Sheet1 has the raw, unconcatenated data
    'Sheet2 gets the concatenated data
    'istring(i) are the concatenated strings
    Dim istring(20) As String
    erow = 0
    i = 1
    start:
    erow = erow + 1
    Set rng = Sheets("sheet1").Range(Cells(erow, 1), Cells(1000, 1)).Find("For Example:")
    If rng Is Nothing Then GoTo done
    irow = rng.Row
    erow = Cells(irow, 1).End(xlDown).Row
    istring(i) = "For example: "
    For j = irow To erow
    istring(i) = istring(i) & Cells(j, 1).Value
    Next j
    i = i + 1
    If i = 5 Then GoTo done
    GoTo start
    done:
    Sheets("sheet2").Select
    Cells(1, 1) = "Example"
    For k = 1 To i - 1
    Cells(k + 1, 1) = istring(k)
    Next k
    End Sub
    not a professional, just trying to assist.....

  3. #3
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    Note - the statement

    If i = 5 Then GoTo done


    should be removed - I placed it there to avoid an endless loop during testing - sorry about that.

  4. #4
    Registered User
    Join Date
    05-17-2005
    Posts
    8

    Work on one but no the other

    Thank you Duane! This is exactly what I needed.
    Incidentally it works fine on my system at work, but not at home. When I run the Macro at home, the first “For Example” and subsequent row is omitted, but when I brought it to work this morning it worked just fine. Not a problem though, I’ll try to figure this one out on my own. Your example was far outside of the variations I was attempting, so you taught me another approach. Thanks Again.

  5. #5
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    You are quite welcome. This version has some minor improvements.

    Sub Macro1()
    'Sheet1 has the raw, unconcatenated data
    'Sheet2 gets the concatenated data
    'istring(i) are the concatenated strings
    Sheets("sheet1").Select
    Dim istring(20) As String
    erow = 0
    i = 1
    start:
    erow = erow + 1
    Set rng = Sheets("sheet1").Range(Cells(erow, 1), Cells(1000, 1)).Find("For Example:")
    If rng Is Nothing Then GoTo done
    irow = rng.Row
    erow = Cells(irow, 1).End(xlDown).Row
    istring(i) = ""
    For j = irow To erow
    If j = irow Then istring(i) = Cells(j, 1).Value Else _
    istring(i) = istring(i) & " " & Cells(j, 1).Value
    Next j
    i = i + 1
    GoTo start
    done:
    Sheets("sheet2").Select
    Cells(1, 1) = "Example"
    For k = 1 To i - 1
    Cells(k + 1, 1) = istring(k)
    Next k
    End Sub

  6. #6
    Registered User
    Join Date
    05-17-2005
    Posts
    8

    A new Curve Thrown in

    Duane,
    Your Macro worked great until I was thrown a new curve. The example I posted above concatenates flawlessly until I add data from the real text file (pasted below). I had been using individual recorded macros to separate the rest of the data but tried to use this new method you showed me all at once. Now I’m even more lost. Here is the data and what I’m trying to accomplish:
    Raw Data:
    ==========PDI=G004 Result==========
    PDI Number: G004
    Finding Category: CAT II
    Reference: UNIX STIG: 3.2.1
    Description: Passwords can be changed
    For example:
    alberaz:*LK*:::::::
    ==========PDI=G015 Result==========
    PDI Number: G015
    Finding Category: CAT II
    Reference: UNIX STIG: 3.1.3
    For example:
    The SLEEPTIME variable is not set in
    ==========PDI=G018 Result============


    Manual End Result (table; top row is column heading)
    |PDI Number|-------|Finding Category|------|Reference|------|Description---|------|For Example|
    |G004--------|-------|CAT II------------|------|UNIX STIG|-----|An Account ...|------|alberaz:*LK*:::::::|

  7. #7
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    Hi, I am not sure I quite understand the layout of your raw data, and desired output. Is it now every new "section" starts with a line beginning with this?

    ==========PDI

    And then you want

    PDI Number in column A, Finding Category, Reference, Description in columns B-D,
    and then the For example concatenation in column E?

  8. #8
    Registered User
    Join Date
    05-17-2005
    Posts
    8
    Thank you, yes, every new section starts with ======PDI, and the columns you mentioned are what I'm seeking. In actuality, the original raw text starts with from 10 to 50 (varying) lines of info-text that lead up to the first "======PDI". As an aside, I wrote the following macro to delete those lines.
    ______________________________
    Public Sub deleterows()
    ' deletes the headers leading up to the first =====PDI=====
    Dim selection As range
    Set selection = Cells.Find(what:="PDI", lookat:=xlPart)
    range("a1").EntireRow.Select
    Do Until ActiveCell.Value = selection
    ActiveCell.EntireRow.Delete
    Loop
    End Sub
    __________________________________

+ 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