+ Reply to Thread
Results 1 to 7 of 7

Flatten an array of data into 1 row

  1. #1
    Registered User
    Join Date
    12-10-2018
    Location
    Singapore
    MS-Off Ver
    365
    Posts
    19

    Flatten an array of data into 1 row

    Hello Excel Wizards,
    I like to know whether VBA could help in this case...
    So I have a table that I wish to convert to the table on the right. Basically, it's to flatten the rows into 1 single row. And row starts with a common denominator "orbs".
    And when there is a blank in the column, I want that to be reflected as a blank in the new table too (eg. D6 = P3)
    The actual data has 50 over columns and thousands of rows, so should I use a formula for this or am I right to sense that VBA is better for this?

    So if I imagine I have a rolling pin, I would flatten each array of "orbs" data, and put the rows together (i.e. remove the blank rows).
    Sometimes the "orbs" appear earlier or later depending on how thick the data is...

    PS: I tried using some concatenation and offset formula and it massively slowed down the sheet till it's not usable.

    Capture.PNG
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,913

    Re: Flatten an array of data into 1 row

    Try this code:
    Please Login or Register  to view this content.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Flatten an array of data into 1 row

    As I was busy...
    Please Login or Register  to view this content.
    Last edited by sintek; 05-11-2019 at 05:04 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Flatten an array of data into 1 row

    @ Phuocam

    The actual data has 50 over columns and thousands of rows
    Perhaps a small change required...
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-10-2018
    Location
    Singapore
    MS-Off Ver
    365
    Posts
    19

    Re: Flatten an array of data into 1 row

    Thanks for the great code. Works perfectly.
    Just a slight extension... what if I have this static data at the left,
    How could I incorporate that into the final output too?
    There's some variation in the actual static data, so just to be sure, how could we copy over the columns on the left?
    Do we just extend the range of this VB?



    Capture2.PNG
    Attached Files Attached Files

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Flatten an array of data into 1 row

    If you are using this for any serious application wouldn't it be better to 'flatten' it into a normalised table that could be used as the source for a Pivot Table. i.e. a table with columns labels for...

    A1. The generic name of whatever c1 represents. There's only 'orbs' at the moment but might there be others
    B1. The generic name of whatever c2...c8 represent, values in the rows would be either c2 or c3.. cnn
    C1. The generic name of whatever the u1...u2 represent, values in the rows would be either u1.1 or u1.2 ..un.n


    See attached Sheet2
    Attached Files Attached Files
    Last edited by Richard Buttrey; 05-12-2019 at 05:20 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Flatten an array of data into 1 row

    Please Login or Register  to view this content.

+ 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. [SOLVED] Flatten 2D Table with Multiple Headers to a 1D Data Table
    By glidlegolas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2017, 03:41 PM
  2. Transpose or flatten out cell data
    By Bryan Karsten in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2017, 12:02 PM
  3. Flatten data in 3 column with a unique ID in one column
    By masuka9 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2015, 06:56 AM
  4. Flatten/ de-pivot
    By ccb81 in forum Excel General
    Replies: 1
    Last Post: 08-18-2014, 04:45 PM
  5. [SOLVED] Attempting to flatten multiple temporal data points for single identifier
    By cranialnerve in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-22-2013, 01:36 AM
  6. Flatten Data Script
    By JimmyA in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-15-2011, 12:08 PM
  7. How to 'flatten' a set of values
    By JosVL in forum Excel General
    Replies: 3
    Last Post: 12-04-2009, 04:50 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