Consulting

Results 1 to 11 of 11

Thread: Concatenate Multiple Rows

  1. #1
    VBAX Regular
    Joined
    Dec 2010
    Posts
    19
    Location

    Concatenate Multiple Rows

    Can somebody please help? Ive tried doing Nesting-IF formula and mix of functions to no avail. I think VBA will work out my problem but I do not know how to start a code for this:

    I have to capture the all comments for the same ID. The Comments New field in the attachment is my desired output. Not all the lines have the ID, if the ID field of the line is empty the comments should go with all other comments that goes before that line on the first instance of that ID.

    Appreciate your help.
    Attached Files Attached Files

  2. #2
    VBAX Regular
    Joined
    Nov 2011
    Location
    Ufa
    Posts
    75
    Location
    [VBA]Sub ertert()
    Dim x, y(), i&, j&, s$
    x = Range("A2:B" & Cells(Rows.Count, 2).End(xlUp).Row).Value
    ReDim y(1 To UBound(x), 1 To 1): j = 1
    For i = 1 To UBound(x)
    If Len(x(i, 1)) Then
    y(j, 1) = s: s = x(i, 2): j = i
    Else
    s = s & " " & x(i, 2)
    End If
    Next i
    y(j, 1) = s: [c2].Resize(i - 1).Value = y()
    End Sub[/VBA]
    Attached Files Attached Files

  3. #3
    VBAX Regular
    Joined
    Dec 2010
    Posts
    19
    Location

    It's working!!!
    I just need to twick the code a little bit - - Dunno how. My comments are in column 'C' and my new comments must be added or placed in 'F'. I've tried but - - no success. Can you please help.

  4. #4
    VBAX Regular
    Joined
    Nov 2011
    Location
    Ufa
    Posts
    75
    Location
    try to replace these lines:
    [vba]...
    x = Range("A2:C" & Cells(Rows.Count, 2).End(xlUp).Row).Value
    ...
    y(j, 1) = s: s = x(i, 3): j = i
    ...
    s = s & " " & x(i, 3)
    ...
    y(j, 1) = s: [F2].Resize(i - 1).Value = y()[/vba] or show a new example

  5. #5
    VBAX Regular
    Joined
    Dec 2010
    Posts
    19
    Location
    Quote Originally Posted by emcinco

    It's working!!!
    I just need to twick the code a little bit - - Dunno how. My comments are in column 'C' and my new comments must be added or placed in 'F'. I've tried but - - no success. Can you please help.

    Sorry - My new comments should come in column E not in F.

  6. #6
    VBAX Regular
    Joined
    Dec 2010
    Posts
    19
    Location
    Here is a sample sheet.
    Attached Files Attached Files

  7. #7
    VBAX Regular
    Joined
    Nov 2011
    Location
    Ufa
    Posts
    75
    Location
    .
    Attached Files Attached Files

  8. #8
    VBAX Regular
    Joined
    Dec 2010
    Posts
    19
    Location
    Hi,
    This really works wonderful. I've worked on simple VB's only. This one is complex for me.

    Just another question. The VB does not seem to recognize 'operators'. It throws up error message.

    I've attached a sample in the next post.

  9. #9
    VBAX Regular
    Joined
    Dec 2010
    Posts
    19
    Location
    see attached.
    Attached Files Attached Files

  10. #10
    VBAX Regular
    Joined
    Nov 2011
    Location
    Ufa
    Posts
    75
    Location
    Try to add an apostrophe
    [VBA]If Len(x(i, 1)) Then
    y(j, 1) = s: s = "'" & x(i, 2): j = i 'in this line
    Else
    s = s & " " & x(i, 2)
    End If[/VBA]

  11. #11
    VBAX Regular
    Joined
    Dec 2010
    Posts
    19
    Location
    Superb!
    Thank you very much.

Posting Permissions

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