+ Reply to Thread
Results 1 to 7 of 7

Concatenate Cells between blank rows

Hybrid View

  1. #1
    Registered User
    Join Date
    10-20-2014
    Location
    London
    MS-Off Ver
    2013
    Posts
    3

    Concatenate Cells between blank rows

    Hi,

    I'm trying to Concatenate text from cells in a column that are separated by blanks.

    I've had some success with doing this for single columns, but what I want to do is create a kind of driver column, from which the rules for blank rows is identified, and then apply the concatenation to a number of cells in a selected range.

    In the attached ("Original" Sheet) I've got the key data in column D, which will drive the concatenation rule, but I also need A, B, E and F to be concatenated as A and B line up with the top of the data in D, whereas E and F line up with the bottom of the data in D.

    Sometimes they will align like this, other times the data in E will be center to the data in D,

    Any starting points would be a great help, as I can't seem to get over applying the rule to multiple columns,

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Concatenate Cells between blank rows

    Does this help?

    Sub mattmagoo()
    Dim i As Long, y As Long
    y = Range("D" & Rows.Count).End(3).row
    Range("D2:D" & y).SpecialCells(4).EntireRow.Delete
    For i = y To 2 Step -1
        If Cells(i, "D").Font.Underline = xlUnderlineStyleSingle Then GoTo zz
        If Cells(i, "A") = "" Then
            Cells(i - 1, "D") = Cells(i - 1, "D") & " " & Cells(i, "D")
            Range(Cells(i, "E"), Cells(i, "F")).Cut Cells(i - 1, "E")
            Rows(i).Delete
        End If
    zz:
    Next i
    End Sub

  3. #3
    Registered User
    Join Date
    10-20-2014
    Location
    London
    MS-Off Ver
    2013
    Posts
    3

    Re: Concatenate Cells between blank rows

    Hi John,

    Thanks for your help,

    The logic seems to be running off whether or not there is a blank in Row A, ideally I need it to run off the blanks in Row D and delete them right at the end, as sometimes A is blank,

    Matt

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Concatenate Cells between blank rows

    Did you test it on your sample. The logic handles Column D as well.

  5. #5
    Registered User
    Join Date
    10-20-2014
    Location
    London
    MS-Off Ver
    2013
    Posts
    3

    Re: Concatenate Cells between blank rows

    It doesn't concatenate the data in rows 5 & 6 as there is no corresponding data in A (even after the underline rule is removed)

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Concatenate Cells between blank rows

    Try:

    Sub mattmagoo()
    Dim i As Long, y As Long
    y = Range("D" & Rows.Count).End(3).row
    For i = y To 2 Step -1
        If Cells(i, "D").Font.Underline = xlUnderlineStyleSingle Then
            If Cells(i - 1, "D").Font.Underline = xlUnderlineStyleSingle Then
                Cells(i - 1, "D") = Cells(i - 1, "D") & " " & Cells(i, "D")
                Cells(i, "D").ClearContents
            End If
        End If
    Next i
    Range("D2:D" & y).SpecialCells(4).EntireRow.Delete
    For i = y To 2 Step -1
        If Cells(i, "D").Font.Underline = xlUnderlineStyleSingle Then GoTo zz
        If Cells(i, "A") = "" Then
            Cells(i - 1, "D") = Cells(i - 1, "D") & " " & Cells(i, "D")
            Range(Cells(i, "E"), Cells(i, "F")).Cut Cells(i - 1, "E")
            Rows(i).Delete
        End If
    zz:
    Next i
    End Sub
    Note: Underline readded.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Concatenate Cells between blank rows

    Try this.
    Sub test()
        Dim x, r As Range
        Application.ScreenUpdating = False
        x = Application.Match("description", Rows(1), 0)
        If (IsNumeric(x)) * (Columns(x).SpecialCells(2).Areas.Count > 1) Then
            With Range(Cells(1, x), Cells(Rows.Count, x).End(xlUp))
                For Each r In .SpecialCells(2, 2).Areas
                    If r.Count > 1 Then
                        r(1).Characters(Len(r(1)) + 2, Len(r(2))).Text = " " & r(2)
                        r(2).Clear
                        r(2, 2).Resize(, 2).Copy r(, 2)
                    End If
                Next
                .SpecialCells(4).EntireRow.Delete
            End With
        End If
        Application.ScreenUpdating = True
    End Sub
    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)

Similar Threads

  1. To concatenate column headers if value in rows below is non-blank
    By chibidee in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-17-2015, 06:19 AM
  2. [SOLVED] Concatenate Multiple Rows And Switch Columns If Blank
    By Knawl in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-17-2014, 05:11 AM
  3. CONCATENATE non-blank cells
    By ScottBeatty in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-10-2014, 02:37 PM
  4. deleting blank rows in a concatenate formula
    By jettakay in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-20-2013, 04:56 PM
  5. [SOLVED] Concatenate non-blank cells
    By tone640 in forum Excel General
    Replies: 4
    Last Post: 05-16-2012, 05:31 AM
  6. Replies: 0
    Last Post: 04-07-2009, 04:42 PM
  7. Concatenate Non Blank Cells
    By ssjody in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-31-2005, 08:30 AM

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