+ Reply to Thread
Results 1 to 5 of 5

Concatenate values in columns based on headers

  1. #1
    Registered User
    Join Date
    05-15-2019
    Location
    United States
    MS-Off Ver
    365
    Posts
    8

    Concatenate values in columns based on headers

    Hello.

    I am trying to create a macro that will join together cells in the same row IF their headers match a list I input. If possible, I would also like this macro to write the results to a separate workbook on a shared drive.

    Any ideas?

    Thanks to all!

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,872

    Re: Concatenate values in columns based on headers

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    05-15-2019
    Location
    United States
    MS-Off Ver
    365
    Posts
    8

    Re: Concatenate values in columns based on headers

    Before and After workbook attached. If possible, I would also like the macro to spit out the results in a new workbook, with the tab named "Data."

    The results need to follow the logic:

    First column remains the same
    Second column remains the same
    Third column takes on a new header name
    In third column, if cell in column B includes Yellows, then group cells in columns C, D, and F together and add "Yellow" to end
    In third column, if cell in column B includes Greens, then group cells in columns D and G together and add "Green" to end
    In third column, if cell in column B includes Blues, then group cells in columns G, E, and F together (order is important) and add "Blue" to end
    In third column, if cell in column B includes Reds, then group cells in columns C and F together and add "Red" to end
    In third column, if cell in column B includes Oranges, then group cells in columns C and G together and add "Orange" to end

    Thanks!
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    According to your attachment a beginner starter demonstration to paste to the source worksheet module :

    PHP Code: 
    Sub Demo1()
        
    Dim R&, S$, V
            Application
    .ScreenUpdating False
            Workbooks
    .Add.Worksheets(1).Name "Data"
            
    Me.UsedRange.Columns("A:B").Copy ActiveSheet.[A1]
        For 
    2 To Me.UsedRange.Rows.Count
            S 
    Split(Cells(R2).Value2"/")(0)
            If 
    S Like "*s" Then S Left(SLen(S) - 1)
        
    Select Case S
               
    Case "Blue":     = [{7,5,6}]
               Case 
    "Green":    = [{4,7}]
               Case 
    "Orange":   = [{3,7}]
               Case 
    "Red":      = [{3,6}]
               Case 
    "Yellow":   = [{3,4,6}]
               Case Else:       
    ""
        
    End Select
            
    If IsArray(VThen ActiveSheet.Cells(R3).Value2 Join(Application.Index(Rows(R), , V)) & " " S
        Next
            ActiveSheet
    .UsedRange.Columns("B:C").AutoFit
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Registered User
    Join Date
    05-15-2019
    Location
    United States
    MS-Off Ver
    365
    Posts
    8

    Re: Hi ! Try this !

    Thank you. This helps. Can we make me adjustments that are in the new attachment?
    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. Sum across columns based on column headers or count of columns
    By RandiLee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2016, 09:59 AM
  2. top 3 and last 3 values in a table should return row headers concatenate with comma
    By anchuri_chaitanya in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-12-2016, 07:44 PM
  3. Replies: 3
    Last Post: 07-28-2016, 01:47 AM
  4. How to concatenate adjacent cells based on values present in previous columns?
    By Palraj in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-30-2014, 01:01 AM
  5. Get value based on columns and row headers
    By KJL in forum Excel General
    Replies: 2
    Last Post: 05-06-2014, 01:36 PM
  6. [SOLVED] CONCATENATE headers based on 1 condition
    By bonny24tycoon in forum Excel General
    Replies: 2
    Last Post: 04-27-2012, 10:06 AM
  7. Macro to Sum Columns based on Headers
    By Jluc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2011, 02:36 PM

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