Results 1 to 8 of 8

Thread: Sort table vertically

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,970
    In the attached are several offerings:

    1. Your macro with minimal changes to make it work as I think was intended.
    It seems that headers such as Inno-Tech (a) and MYMAN-Group (d) were originally intended to have numbers instead of letters, so that they become Inno-Tech (1) and MYMAN-Group (4) with the numbers deciding on the order (left to right) of the headers. [This is because the macro Dims n as a Long and the line: n = Replace(Split(b(1, j), "(")(1), ")", "") is designed to fetch the character between parentheses into n]
    So I copied your Before sheet to Before (macro) and changed all those headers, then ran the updated Company_names_in_Table_Sort_Interpretive macro. Currently the penultimate line of that macro puts the results offset to the right to preserve the original data, but you can overwrite the existing data (see alternative line currently commented-out).
    I've indicated the minor changes I've made to the macro as comments.
    The macro works on the active sheet.

    2. A Power Query solution, similar results to the macro but with a nod to your
    Since I want to further process the sheets, I need a uniform structure of the data.
    The result is on the sheet PQ Results which is based on the data in the Before (PQ) sheet (which is a copy of your Before sheet but I've assumed that where you have Company in cells A4, A38 etc. that these are really real company names that you've 'sanitised' for this forum, so I've put some fictitious company names in there; I hope I'm right).
    Power Query queries need refreshing (like a pivot table) when the base data changes, so I've written a very short macro called UpdateNamedRange which finds the range on the active sheet to work on (in the same way as your macro does) and gives it a name (RangeToProcess), and it's this named range that the query uses as its source data. The macro then goes on to refresh the query. Well, queries, because…

    3. …another Power Query query (actually it uses the first query and adds one more step) on sheet FlatFile which is the same data in a format ideal for the likes of further processing, such as the creation of pivot tables like the one found on the sheet called Pivot, which I've just arranged to be similar to the source data. You might need to refresh this pivot yourself.

    The Power Query offerings do lose some data from your Before sheet: The lines containing Comparative Results - Industry Detail and Performance Measures for Period 1, ind1:. Don't remove the lines beginning Comparative Results - because the queries use that to split out the different companies.
    They should cope with different headers and amounts of headers.

    It could be more robust and easier (in the long run) if the data that's in the Before sheet has itself come from elsewhere, perhaps external files, other Excel workbooks, database files, web, whatever, because Power Query would likely be able to gain access to the data in these files more reliably and quicker than getting it from a sheet.
    Attached Files Attached Files
    Last edited by p45cal; 11-16-2021 at 03:35 PM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •