+ Reply to Thread
Results 1 to 12 of 12

Need a Macro to Transpose and Combine like Values from rows to columns

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Need a Macro to Transpose and Combine like Values from rows to columns

    I am working with a spreadsheet in which I calculate via macro a value (RRT) based off of RT values and transform & trim the data to only have what I need on a tab (Reformat Data). I then created a pivot table to do the transposing from rows to columns but the user needs to be able to manipulate the data values as needed. They may need to move or delete values (+/- 0.05 difference apart) within the table which the pivot will not allow. So I am looking for a macro that will do the same as the pivot table (combine all like values and transpose the data). This macro will make 1 row for each sample name within each vial and display all the area values under their corresponding RRT value, but this macro table will allow deletions and moving of the values within the table. I am attaching a sample file where I have the reformat data tab that displays the data in rows and columns vertically and the pivot table that has the data the way I need. Can someone please help me with this as I am very new to VBA and not sure how to accomplish it.

    Thank you in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    You got 99% of the way there yourself. If you want an editable copy of the pivot table, then make a copy of the pivot table.

    First I made a named dynamic range that overlays the pivot table: Pivot_Range=OFFSET('Pivot Table'!$A$2,0,0,COUNTA('Pivot Table'!$A:$A)-1,COUNTA('Pivot Table'!$2:$2))

    Then I use the following to copy to a sheet called Working Data
    Please Login or Register  to view this content.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    OMG! Wow!!! I'm glad my work didn't go to waste. I'm excited to try this out myself. Where is it that I set the dynamic range? Do I dim that at the beginning of the macro too or somewhere in the worksheet? I can't seem to find it in your sample.

    Thanks

  4. #4
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    I found where it is. Now my question is does this have to be changed for every pivot table. The files can be up to 6,000-8,000 rows long so will this formula capture that?

    Thanks

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    The formula will capture it. The only assumptions that are made are that the data in which you are interested starts in Cell A2, and that it is contiguous (no blank cells) in Column A and Row 2 in the pivot table. If this is not the case, a bit of VB can catch it.

  6. #6
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    OK going to give it a try now and will let you know. Thanks soo much for the quick response!!!

  7. #7
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    OK so I'm getting an error and can't get the macro to work on my sample workbook. I have gone into Formulas>Name Manager and created a new list named Pivot_Range and copy/pasted your offset formula in the refers to box area. I added your code into the VBA area and created the new sheet Working Data. When I run the macro I get a Run time error '1004': Mehtod 'Range' of object '_Global' failed. What am I doing wrong?

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    I'll need to see the line on which the error occurs. If you can, post a copy of the book and I will look at it.

    When you go to the name manager and click on Pivot_Range, if the sheet is not hidden, you should go to the Pivot Sheet and the data range should be outline with a marquee (marching dashes). If that's not happening ,then something about the name definition is wrong, check that the page references are correct.

    The other thing that can cause this error is that the sheet names are different than what the code is looking for.

  9. #9
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    I think it's something with the pivot range because I don't see the outline with a marquee.

    I'm attaching the sample worksheet I was working with, please check and let me know what I actually need to do to fix it. I have the real template I need to update with that is 8000 rows long.

    I wanted to also ask I am trying to create a button that the user will press when they initially load the data into a blank template and it will step through all the macros I have to get to the end results that they want. If I add this piece of code at the end will it work ok once we fix this issue?
    Attached Files Attached Files

  10. #10
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    Easy fix as it turned out. Go to the name manager - somehow quotes got introduced in the refers to box. Carefully remove the quotes and the named range should work.

  11. #11
    Registered User
    Join Date
    10-01-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    It works!! Thank you soo much.

  12. #12
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Need a Macro to Transpose and Combine like Values from rows to columns

    Make sure to go to the tread tools link and mark as solved. Good luck with your project.

+ 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] Combine and Transpose Data from rows to columns
    By Isara-NJ in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-19-2017, 01:23 PM
  2. Extract values and the use index to transpose values across columns to rows
    By bjnockle in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-19-2017, 08:46 PM
  3. Macro to transpose rows to columns
    By escodc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2013, 03:15 PM
  4. MAcro to - copy, transpose, text to columns, remove column A, combine all columns in 1
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-07-2013, 08:48 AM
  5. Replies: 3
    Last Post: 11-18-2012, 09:22 PM
  6. [SOLVED] Transpose rows to columns: variable amount of colums and corresponding values
    By Browser in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-10-2012, 10:40 AM
  7. Macro to transpose a set of rows to columns
    By romanzy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2010, 06:45 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