+ Reply to Thread
Results 1 to 8 of 8

Combine "unknown" columns per row to 2 columns

  1. #1
    Registered User
    Join Date
    07-31-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2013
    Posts
    4

    Combine "unknown" columns per row to 2 columns

    I'm not sure what to search or name this so apologies in advance.

    I need to combine data as follows. fruit_attributes.jpg

    APPLE RED FRUIT ROUND
    BANANA FRUIT YELLOW

    to

    APPLE RED
    APPLE FRUIT
    APPLE ROUND
    BANANA FRUIT
    BANANA YELLOW

    Can this be achieved with formulas or do I need a macro? I don't mind if the data is pasted into the same sheet. Basically each item has various attributes but I need to condense to just 2 columns of item and single attribute.

    Please feel free to post an existing thread link. I tried some searches and found nothing.

    Thanks!

  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,884

    Re: Combine "unknown" columns per row to 2 columns

    Here is a VBA solution

    Please Login or Register  to view this content.

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    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
    07-31-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Combine "unknown" columns per row to 2 columns

    Thanks for the quick reply. That worked! I'm not very skilled in VBA. Do you think something like that is possible with formulas or not really since it is a variable number of columns per item? I clicked on the star - thanks so much for the help!

    I'm going to mark as solved (once I figure out how - I'm new to this forum!)

  4. #4
    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,884

    Re: Combine "unknown" columns per row to 2 columns

    Thanks for the Rep

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Combine "unknown" columns per row to 2 columns

    VBA seems to be best suited for this task, but if we want formulas - why not (will not be a piece of cake anyway).
    I added header row and one dummy column (can be hidden or somewhere out of sight - say column Z etc.)
    in this dummy column (A) in A2 I wrote 1 and in A3 (and copied down) formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    In K2 (and copied down) formula returning first word:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    but as we probably will copy this formula with some excess (too far down) it will be better to ad a condition checking:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and in L2 and copied down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Or with added returning empty cell if column K is already empty:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    See attached file
    Attached Files Attached Files
    Best Regards,

    Kaper

  6. #6
    Registered User
    Join Date
    07-31-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Combine "unknown" columns per row to 2 columns

    Thanks, Kaper. I also gave you a star. I feel like a teacher. I think this is what I had seen before and that's why I asked if there were a formula. I couldn't remember what the formula was.

    I do think VBA is easier to "read" to see what is going on. I am not an expert with INDEX and MATCH functions. I do understand what the VBA is doing even if I can't write it exactly on my own yet. The INDEX and MATCH is a little more difficult for me to follow.

    Thanks, all. Happy to be posting on this forum! :D

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Combine "unknown" columns per row to 2 columns

    Thanks for reputation and for marking thread solved.
    INDEX & MATCH as well as VLOOKUP are between most used excel functions - see for instance recent thread in our WaterCooler: https://www.excelforum.com/the-water...ml#post4735368 ,
    so probably it's now a good time to switch roles (from teacher become pupil :-P ) and learn more about them.

  8. #8
    Registered User
    Join Date
    07-31-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Combine "unknown" columns per row to 2 columns

    I like the power of VBA but I would like to figure out function equivalents (where possible) if I'm in a position where I can't use macros... Thanks for the help and the link!

+ 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. Replies: 1
    Last Post: 03-23-2015, 06:19 PM
  2. How to use named ranges in VBA code using "Columns" and a variation on "Range"
    By haljam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2014, 02:48 PM
  3. Replies: 0
    Last Post: 11-22-2013, 01:36 PM
  4. Replies: 0
    Last Post: 01-09-2013, 06:52 PM
  5. [SOLVED] Problem creating Line Chart from columns "date" and "money"
    By brosef in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 11-05-2012, 09:01 AM
  6. Excel 2002 "Protect Sheet", but allow "Hide Columns"?
    By Dave Peterson in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 12:05 PM
  7. [SOLVED] Excel 2002 "Protect Sheet", but allow "Hide Columns"?
    By VP Safe in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 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