+ Reply to Thread
Results 1 to 13 of 13

Formula that combines text cells into single cell paragraph

Hybrid View

  1. #1
    Registered User
    Join Date
    08-02-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Formula that combines text cells into single cell paragraph

    I have a spreadsheet that compiled Employer of Choice data for several companies, with each company on a separate tab. Under category headers, we listed several components for each company that we found, i.e.: Childcare,Telecommuting, Free transportation, etc.

    I'm pulling this data into Tableau (an infographic program) and would now like the lists to combine into one paragraph, separated by semicolons, that will show on the tooltip mouse-over. For example:

    Childcare
    Telecommuting
    Free transportation

    ...would show as:

    Childcare; Telecommuting; Free transportation

    The problem is, some of these lists have 12 things, some have 3. I've tried to write formulas like IF(COUNTA(B17:B28)=6, B17&"; "&B18.... etc. that count down, but these have too many IF arguments. I don't want things that have only 3 items to end with "; ; ; "

    Can someone please help?! I know there is a character limit for cells, so I've tried to write "and more" into the formula if it's greater than 6, but these are still too many if statements.

    Attached is an example of one company tab.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Formula that combines text cells into single cell paragraph

    Could you please adjust your attached worksheet to include a sheet that mimics what your desired result would be? I believe this should be fairly easy but I want to make sure I have the same outcome you would like.

  3. #3
    Registered User
    Join Date
    08-02-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Formula that combines text cells into single cell paragraph

    Sure! I added a tab that shows what I would like.

    Keep in mind that the spreadsheet I have has 100 of these company tabs, and a Summary sheet that uses in Indirect to look up the company name in a list in column A and pull its data from its sheet. I want these paragraphs to eventually be pulled into the Summary sheet. I imagine I will have to write the formula to combine the text and copy-paste over to each company tab, then write the indirect to pull from those new paragraph cells, correct? Is there a faster way to do it?
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Formula that combines text cells into single cell paragraph

    Would you mind a macro?

  5. #5
    Registered User
    Join Date
    08-02-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Formula that combines text cells into single cell paragraph

    Nope! As long as you explain it clearly, haha.

  6. #6
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Formula that combines text cells into single cell paragraph

    Where would you like the information from rows 4 to 14 at?

  7. #7
    Registered User
    Join Date
    08-02-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Formula that combines text cells into single cell paragraph

    Nowhere! The only information I want is a paragraph each for:

    Development, Recognition, and Feedback
    Work-Life Balance
    Benefits
    Workplace Culture and Perks
    Communication and Leadership

  8. #8
    Registered User
    Join Date
    08-02-2012
    Location
    Atlanta, GA, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Formula that combines text cells into single cell paragraph

    I tried doing it using a named formula (and can't think of a way to get it to work with a formula array) but you CAN just brute-force it using something like this:

    Pasted into cell A2, and used to concatenate B2 through L2. It produces the desired result, though of course if the cells you're checking are far-flung this will be more difficult. A macro could do it easily.

    =CONCATENATE(IF(C2="",B2,B2&"; "),
    IF(D2="",C2,C2&"; "),
    IF(E2="",D2,D2&"; "),
    IF(F2="",E2,E2&"; "),
    IF(G2="",F2,F2&"; "),
    IF(H2="",G2,G2&"; "),
    IF(I2="",H2,H2&"; "),
    IF(J2="",I2,I2&"; "),
    IF(K2="",J2,J2&"; "),
    IF(L2="",K2,K2&"; "),
    IF(M2="",L2,L2&"; "))

  9. #9
    Registered User
    Join Date
    08-02-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Formula that combines text cells into single cell paragraph

    Can you direct me to the macro that will do this?

  10. #10
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Formula that combines text cells into single cell paragraph

    Hey there,

    I've got one for you just adding the comments to help you understand.

    Thanks!

  11. #11
    Registered User
    Join Date
    08-02-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Thumbs up Re: Formula that combines text cells into single cell paragraph

    rvasquez, whoever you are, wherever you are, you just saved my day. THANK YOU!!!!!

  12. #12
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Formula that combines text cells into single cell paragraph

    Alrighty,

    Attached is your original workbook updated to include a macro that mimics the Desired Results you provided.

    To run the Macro
    1.Enable macros and then Press Alt+F8 on your keyboard
    2. From the macro window select Test
    3. Select the run option.

    This macro will run and format everything as asked. To run it another time you will need to delete the created worksheet.

    To use this macro into your workbook, open your workbook:

    1.Press Alt+F8 on your keyboard
    2.Clear the macro name box and type LocateCells in the blank box provided
    3.Select the Create option
    4.In between the Sub LocateCells() and End Sub copy and paste the code:

    Dim ws As Worksheet, LR As String, i As Long, arr() As String, wsLR As String
    Dim c As Range, fc As Range, d As Long
    Dim x As Long, Darr() As String, y As Range, z As Range, t As Long
     
    Sheets.Add(before:=Sheets(1)).Name = "Combined Data"    'Add a worksheet in front of the first worksheet and name it combined data
    
    'In row 1 from columns A to F Add the following headings but splitting the text that following Split( but ;
    ActiveSheet.Range("A1:F1") = Split("Company;Work-Life Balance;Development, Recognition and Feedback;Communication and Leadership;Workplace Culture/Perks;Benefits", ";")
    
    'build a list of values to loop through, column headers
    'this list will be used later to find the value on the worksheet and then find the values underneath
    arr = Split("Work-Life Balance;Development, Recognition and Feedback;Communication and Leadership;Workplace Culture/Perks;Benefits", ";")
    
    'Loop through each worksheet in this workbook that is not the first worksheet in this workbook
    For Each ws In ThisWorkbook.Worksheets
        If ws.Index > 1 Then 'if the worksheet in the loop is not the first worksheet then
            With Sheets(1)  'with the newly added worksheet
                LR = .Range("A6555").End(xlUp).Row + 1  'set LR equal to the first cell in column A that is blank
                    
                    With ws 'with current worksheet in the loop
                        wsLR = .Range("A6555").End(xlUp).Row
                        .Range("B1").Copy    'copy cell B1 (company Name)
                    End With    'end with the current cell in the loop
                
                .Range("A" & LR).PasteSpecial xlPasteValues ' in the added worksheet paste the value in to column A of the LR(variable defined above) row
                        
                    With ws 'with the current worksheet in the loop
                        For i = LBound(arr) To UBound(arr)  'from the first item in the arr list to the last
                                                            'arr list defined above
                            For Each c In .Range("A10:D" & wsLR).Cells  'loop through cells from A10 to column D and the last row in the worksheet
                                If c.Value = arr(i) Then    'if the value in the current cell in the loop is equal to the current list item in the arr array then
                                       
                                       'set the variable fc equal to the found cell whose value is equal
                                       'to "SCORE" after the current cell in the loop, in the current cell in the loops column
                                       Set fc = .Columns(c.Column).Find(What:="SCORE:", After:=.Cells(c.Row, c.Column), LookIn:=xlValues, LookAt:= _
                                                    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
                                                    , SearchFormat:=False)
    
                                            ReDim Darr(1 To fc.Row - c.Row - 1) 'reassign the number of items in list Darr
                                                                                'creating a new list for the list under the categories
                                                    
                                                    For x = 1 To fc.Row - c.Row - 1 'set variable x to loop through numbers 1 to the found cell's row and
                                                                                    'c's row minus 1
                                                        If x Mod fc.Row - c.Row - 1 Then ReDim Preserve Darr(1 To UBound(Darr) + (fc.Row - c.Row - 1))  'reassign number of items in the list Darr
                                                                Darr(x) = c.Offset(x, 1).Value  'set the item in the darr list equal to the value in the cell next to the current cell in the loop, and down down number that x loop is on
                                                    Next x  'move to next number in the x loop
                                                
                                            For d = LBound(Darr) To UBound(Darr)    'for each list item in the d loop
                                                With Sheets(1)  'with the first tab in this workbook
                                                    For Each y In .Range("A1:F1").Cells 'loop through cells A1 through F1 (header rows)
                                                        If y.Value = arr(i) Then    'if the value of the cell in the current cell in the d loop
                                                                                    'is equal to the current list item in the arr list then
                                                            If .Cells(LR, y.Column).Value = vbNullString Then   'if the cell is empty then
                                                                .Cells(LR, y.Column).Value = Darr(d)    'add the first item in the d loop
                                                            Else
                                                                If Darr(d) <> vbNullString Then 'if it's not empty and the list item is not nothing then
                                                                    .Cells(LR, y.Column).Value = .Cells(LR, y.Column).Value & "; " & Darr(d)    'combine the value in the cell with the item in the d list in the cell and seperate by ;
                                                                End If  'end if
                                                            End If  'end if
                                                        End If  'end if
                                                    Next y  'move to next y in the y loop
                                                End With    'end with first sheet in the workbook
                                            Next d  'move to next d in the d loop
                                End If 'end if
                            Next c  'move to next c in the c loop
                            
                        Next i  'move to next i in the i loop
                    End With    'end with ws in the ws loop
                
                    
            End With    'end with added worksheet
        End If  'end if statement
    Next ws 'move to next worksheet in the loop
                    
    With Sheets(1)
         With .Cells
            .Font.Size = 9  'font size 9
            .HorizontalAlignment = xlCenter 'align center
            .VerticalAlignment = xlCenter   'align center vertically
            .WrapText = True    'wrap text
         End With
    
         .Columns("A:F").ColumnWidth = 37.75    'column A through F width is 37.75
         .Rows("2:" & LR).RowHeight = 114.75    'rows 2 to the last row height is 114.75
         
         With .Rows("1:1")  'row 1
            .AutoFit    'autofit
            .Font.Bold = True   'bold text
        End With
            
    
    End With

    Please note that this macro assumes that all worksheets are company names and there are no worksheets that you don't want included in the formatted worksheet. If this is not true for your worksheet , you might want to move all the worksheets that do not contains data you want included in the summary to the vbery beginning of the workbook and then you will need to change the following line in the code:

    If ws.Index > 1 Then 'if the worksheet in the loop is not the first worksheet then
    To the below, replacing 1 with the number that represents the first worksheet you wish to start with index number. Index number refers to the tab position +1. In the worksheet you sent me Accenture would be 1, Desired Results would be two and so on.

    If ws.Index > 1 Then
    Also this macro assumes that all your company worksheets start their user entered data for the categories at a row greater than 10.

    5.Anything that appears in green is comment I left to hopefully help you understand.
    6.Exit out of the Visual Basic Window
    7.Press Alt+F8 again and this time select the LocateCells macro
    8.Select Run


    Let me know if this works for you or if you have any questions.
    Attached Files Attached Files

  13. #13
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Formula that combines text cells into single cell paragraph

    LOL no problem, I love things that take a little bit of extra thinking! Please don't forget to mark this thread solved and maybe give a little star tap if I helped

    Thanks!

    RVASQUEZ
    Last edited by rvasquez; 08-02-2012 at 04:49 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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