+ Reply to Thread
Results 1 to 9 of 9

Transpose Columns with Conditions

  1. #1
    Registered User
    Join Date
    12-14-2018
    Location
    Staffordshire, England
    MS-Off Ver
    365
    Posts
    60

    Transpose Columns with Conditions

    Hi All,

    I have been asked to transform data we receive as a list (Output in attached) into something more representative of that shown in the result sheet also on the attached.

    In short this is basically taking the numbers beginning with 81 and making those the column headers and the then the corresponding numbers below being listed in this new column. The amount of numbers involved can vary massively from 1 upwards to there is no pattern here. The only consistent factor will be that the 81 numbers will be there albeit again they could be in a different order or sequence each time the data is presented.

    Ideally I would like to take the raw data (output) each day it is produced and in turn end up with the result without having to make any additional amendments / manipulations to however the result can be calculated,

    Many thanks,
    Gaz
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Transpose Columns with Conditions

    Hi
    try this macro

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor shank_mis's Avatar
    Join Date
    09-08-2018
    Location
    Delhi
    MS-Off Ver
    2010
    Posts
    128

    Re: Transpose Columns with Conditions

    Quote Originally Posted by Gazsim View Post
    Hi All,

    I have been asked to transform data we receive as a list (Output in attached) into something more representative of that shown in the result sheet also on the attached.

    In short this is basically taking the numbers beginning with 81 and making those the column headers and the then the corresponding numbers below being listed in this new column. The amount of numbers involved can vary massively from 1 upwards to there is no pattern here. The only consistent factor will be that the 81 numbers will be there albeit again they could be in a different order or sequence each time the data is presented.

    Ideally I would like to take the raw data (output) each day it is produced and in turn end up with the result without having to make any additional amendments / manipulations to however the result can be calculated,

    Many thanks,
    Gaz
    Hi,

    This can be done with the help of Macro. In case you do not want to go with VBA option, array formula may come handy.
    I have implemented array formula in the sheet attached herewith. Kindly go through it.
    100 rows have been considered for the array formula. In case you have more data, simply modify the range.



    Shashank
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-14-2018
    Location
    Staffordshire, England
    MS-Off Ver
    365
    Posts
    60

    Re: Transpose Columns with Conditions

    Hi Nicky,

    Many thanks - that does indeed work although I have noted that it does not overwrite existing data on the results if there are less lines of data under that particular 81 ref if you follow when you change / update it?

    For example if I on my first set of data had three references under 81-14-022-04 and the next day this only became one, the previous additional two references would remain when they need to be deleted / cleared,

    Hope this makes sense?

    Thanks,
    Gaz

  5. #5
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Transpose Columns with Conditions

    Hi Gaz
    if you want to clear the contents of the results sheet before copying the values then add this code

    Please Login or Register  to view this content.
    above the line starting "do while ... "

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

    Re: Transpose Columns with Conditions

    If the following presentation will work for you, then Power Query is an available option. The Mcode is shown below and the file is attached.

    v A B C
    1 81-14-022-01 81-14-022-02 81-14-022-03
    2 12345678910
    3 34567891081
    4 35535145645
    5 32318754510
    6 35238624779
    7 53532227789
    8 89896323241
    9 33586353335
    10 99877454211
    Please Login or Register  to view this content.
    Attached Files Attached Files
    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

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Transpose Columns with Conditions

    Another approach that overwrites previous results. This uses formulas rather than macros.

    In column B of 'Output' this helper column that defines group boundaries. The column can be hidden for aesthetic purposes.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then to address the added or removed data these dynamic defined range formulas in Name Manager

    Source_Dat
    =Output!$A$1:INDEX(Output!$A:$A,MATCH(1E+306,Output!$A:$A,1))
    Source_Hlpr
    =Output!$B$1:INDEX(Output!$B:$B,MATCH(1E+306,Output!$A:$A,1))


    Then in A1 of 'Result' sheet filled across until you get blanks.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then for the results themselves this in A2 filled down and across until you get blanks.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    As you add/delete data from 'Output' sheet those last two formulas will reflect that.
    Attached Files Attached Files
    Dave

  8. #8
    Registered User
    Join Date
    12-14-2018
    Location
    Staffordshire, England
    MS-Off Ver
    365
    Posts
    60

    Re: Transpose Columns with Conditions

    Hi All,

    Many thanks for all your replies so far - I am currently looking at each individually to see which will best fit our requirements.

    However, one final question. Once I have the data in result I then need to cross reference this data with further data to confirm which references we have a location (or match) on. I have created a separate 'Data' sheet on the attached file which I hope gives an indication of what is required but the list of data will contain somewhere in the region of 500,000+ lines ultimately to cross check against, the majority of which would have no match.

    Many thanks,
    Gaz
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,526

    Re: Transpose Columns with Conditions

    If I understand correctly and you want to populate column A on the Data sheet:
    1. Use Dave's formula for the helper column (B) on the output sheet
    2. Use the following formula in column A on the Data sheet: =IFNA(INDEX(Output!B$1:B$21,MATCH(B2,Output!A$1:A$21,0)),"")
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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] Copy, paste and transpose selected data to new worksheet based on conditions
    By Grilleman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-06-2019, 12:59 PM
  2. [SOLVED] Transpose Data with match Conditions
    By abhinavbinkar in forum Excel General
    Replies: 3
    Last Post: 06-28-2018, 05:43 AM
  3. Transpose and sum with conditions
    By anahochmanova in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2016, 11:20 AM
  4. Transpose variable based on 2 conditions
    By jam320 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-13-2015, 11:00 AM
  5. Transpose swipe timings based on 3 Conditions
    By vasu2007 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2015, 01:17 PM
  6. [SOLVED] Transpose column to rows based on conditions
    By thaykhov in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2013, 02:35 AM
  7. Transpose values from column to rows (one cell) with conditions
    By zeko90 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2013, 08:21 AM

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