+ Reply to Thread
Results 1 to 17 of 17

Copy and transpose tables from different sheets into a single sheet

  1. #1
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Copy and transpose tables from different sheets into a single sheet

    Hello!

    I have a workbook with 12 sheets. Each sheet has data in the range B2:BY13. I need to transpose the data in each sheet and copy every transposed table into a single sheet with a blank row between each data block. I also would want to keep the formatting of the data.

    The sheets with the data blocks have different names and dont start with "Sheet". Also, the data blocks in the range B2:BY13 contain cells with no values. When transposing with MTRANS, Excel writes #NV for those cells. I would want to avoid this and rather have empty cells or cells which do not contain any visible text.

    Example:

    Sheet 1

    Please Login or Register  to view this content.

    Sheet 2

    Please Login or Register  to view this content.
    Sheet Summary

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    -----------

    How could this be done in VBA? Thank you for your help!

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy and transpose tables from different sheets into a single sheet

    does the data contain formulas?
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Copy and transpose tables from different sheets into a single sheet

    Hello!

    Yes, the data blocks contain only formulas! These sheets collect raw data from other sheets and do some transformations.

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy and transpose tables from different sheets into a single sheet

    try this then

    Please Login or Register  to view this content.
    keep the formatting of the data
    ^^ this code only keeps number format
    if you want cell format that would require tweaking of code
    Last edited by humdingaling; 04-21-2017 at 03:05 AM. Reason: inserted more comments

  5. #5
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy and transpose tables from different sheets into a single sheet

    Please Login or Register  to view this content.
    ^This does cell formatting as well as number formats and values now

  6. #6
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Copy and transpose tables from different sheets into a single sheet

    Hi,

    this is really really awesome!

    I was wondering if one could include a few things:

    1) The formatting in the sheet summary is lost. Is it possible to import the original formatting of the untransposed blocks?

    2) Instead of one line between the data blocks in the sheet summary, I get a random number of blank rows (between 40 and 70).

    3) The workbook contains also sheets which I do not want to combine into the summary sheet. Is there a way to tell the macro that it should only combine the selected sheets?

    Edit: I did not see your second post before posting mine.
    Last edited by excelactuary; 04-21-2017 at 03:15 AM.

  7. #7
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy and transpose tables from different sheets into a single sheet

    1> 2nd code does that

    2> yes though the determination of what is blank is up to you
    i just made it copy all 76 columns regardless
    do you want to base it on ROW 2?

    3> you need to tell me specifically what is in your workbook in order to provide an accurate response
    is there many more sheets or just one or two?
    if one or two...add more ifs to check sheet name
    if many...i suggest you tell me what the sheet names of what you want to include instead
    try to find a pattern or something

  8. #8
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Copy and transpose tables from different sheets into a single sheet

    Hello again!

    on 1): with your new code, we also have the formatting - great! Is it actually possible to NOT include the cell border lines?

    on 2): the problem is the following: the data blocks have the same size, BUT they are referencing to raw data on other sheets. Meaning, some cells will be empty and others not on different sheets, because the raw data blocks have the same number of rows, but a different number of columns.

  9. #9
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy and transpose tables from different sheets into a single sheet

    i think this is what you want from point 2
    Please Login or Register  to view this content.

    this is the only line i changed

    i = ws1.Cells(Rows.Count, "A").End(xlUp).Row + 1 'determine next row based on column A of summary

  10. #10
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Copy and transpose tables from different sheets into a single sheet

    On 3): I have a pattern. The first sheet is "Summary" and then the 12 sheets to be combined follow.

  11. #11
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy and transpose tables from different sheets into a single sheet

    on 1): with your new code, we also have the formatting - great! Is it actually possible to NOT include the cell border lines?
    this is rather hard to do...as you are transposing the data it doesnt really grab the appriopate cell borders (unless its border lines that wraps for every individual cell)
    manually do a set yourself and you will see what i mean

    maybe easier to replicate the formatting rather than keep it but without actually seeing a sample i can only guess

  12. #12
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy and transpose tables from different sheets into a single sheet

    On 3): I have a pattern. The first sheet is "Summary" and then the 12 sheets to be combined follow.
    changed the how the code loops to accommodate this pattern

    using the principle of worksheet index instead of just looping all worksheets

    Please Login or Register  to view this content.
    Last edited by humdingaling; 04-21-2017 at 03:43 AM. Reason: grammar, exit sub

  13. #13
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Copy and transpose tables from different sheets into a single sheet

    Thank you!

    On 2) again:

    sample.png

    In the attached image you see the data blocks from two different sheets. One has many more columns than the other. But both have formulas in the same range: B2:BY13. When you transpose them, you also transpose the empty cells in the range B2:BY13 (the ones which reference to no data actually, but still have formulas in them). Can the macro actually differentiate between a cell which references to real data behind it and a cell which references to an empty cell?

  14. #14
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy and transpose tables from different sheets into a single sheet

    here is the issue with problem 1 in example
    you can clearly see it does not give you the results you want

    hmm problem 2 again...i will need to revisit again next time

    its time to go home for today
    maybe someone else can pick up on it otherwise ill be back on monday
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Copy and transpose tables from different sheets into a single sheet

    Hi!

    Thank you very much for everything so far! I think an easy way to solve the problem, would be to delete the blank rows in "Summary" between the data blocks up to one.

    Is this possible?

    Edit: Yes: https://www.excelforum.com/excel-pro...ta-blocks.html
    Last edited by excelactuary; 04-21-2017 at 05:53 AM.

  16. #16
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Copy and transpose tables from different sheets into a single sheet

    not sure if this is resolved or not?

  17. #17
    Forum Contributor
    Join Date
    02-18-2013
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2016
    Posts
    221

    Re: Copy and transpose tables from different sheets into a single sheet

    Solved! Thank you so very much for everything. Your contribution was really great!

+ 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] Transpose specific row of multiple sheets into one single sheet using VBA
    By haer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-09-2016, 11:17 PM
  2. Replies: 1
    Last Post: 02-26-2016, 12:05 PM
  3. [SOLVED] Distribute tables in single sheet to other sheets
    By İrem Çalık in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2012, 09:56 AM
  4. Replies: 11
    Last Post: 04-25-2012, 09:10 AM
  5. Replies: 2
    Last Post: 03-16-2012, 12:00 PM
  6. Copy items from multiple sheets onto single sheet
    By rbpd5015 in forum Excel General
    Replies: 0
    Last Post: 08-07-2010, 09:37 AM
  7. Copy data from single sheet to multiple sheets
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2009, 11:31 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