+ Reply to Thread
Results 1 to 8 of 8

Macro for transposing multiple columns into a single row

  1. #1
    Registered User
    Join Date
    05-03-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    10

    Macro for transposing multiple columns into a single row

    Hello.

    I read a thread that included a macro similar to what I am needing to do. However, my data is formatted slightly different. I've attached an example of a before and after of what the data should look like. There are approximately 2700 rows on my actual worksheet...

    Any help would be greatly appreciated. I'm not very familiar with macros yet and don't really have a great idea of where to start.

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro for transposing multiple columns into a single row

    BBExcelusr,

    Welcome to the Excel Forum.

    I assume that your raw data is already sorted/grouped per your attached workbook.

    The macro will create a new worksheet Sheet2 with the results.


    Detach/open workbook ReorgData w1 AB w2 AG - BBExcelusr - EF828945 - SDG15.xlsm and run macro ReorgData.


    If you want to use the macro on another workbook:


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


    Please Login or Register  to view this content.

    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


    Then run the ReorgData macro.
    Last edited by stanleydgromjr; 05-03-2012 at 04:31 PM.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    05-03-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro for transposing multiple columns into a single row

    Stan,

    Thanks a bunch for your input! As I said before, I am new to macros and do not have a great deal of knowledge so forgive me if this is a silly question...but which parts of the code above will I need to substitue my own values (row numbers, columns, etc.) into the code? Or does any substitution need to be done at all?

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro for transposing multiple columns into a single row

    BBExcelusr,

    but which parts of the code above will I need to substitue my own values (row numbers, columns, etc.) into the code?
    If your actual raw data is setup differently, then you could post/attach another workbook, and change/redo/modify any sensative information. I would have to see the actual raw data to determine if the macro will run correctly, or if it has to be modified.


    I am new to macros and do not have a great deal of knowledge

    Training / Books / Sites as of 05/02/2012

    MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
    http://www.mrexcel.com/forum/forumdisplay.php?f=19

    Getting Started with VBA.
    http://www.datapigtechnologies.com/ExcelMain.htm

    If you are serious about learning VBA try
    http://www.add-ins.com/vbhelp.htm

    Excel Tutorials and Tips - VBA - macros - training
    http://www.mrexcel.com/articles.shtml

    Here's a good primer on the scope of variables.
    Scope Of Variables And Procedures

    See David McRitchie's site if you just started with VBA
    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    What is a Visual Basic Module?
    http://www.emagenit.com/VBA%20Folder...vba_module.htm

    Ron de Bruin's intro to macros:
    http://www.rondebruin.nl/code.htm

    Creating An XLA Add-In For Excel, Writing User Defined Functions In VBA
    http://www.cpearson.com/excel/createaddin.aspx

    How do I create a PERSONAL.XLS(B) or Add-in
    http://www.rondebruin.nl/personal.htm

    Creating custom functions
    http://office.microsoft.com/en-us/ex...117011033.aspx

    Writing Your First VBA Function in Excel
    http://www.exceltip.com/st/Writing_Y...Excel/631.html

    VBA for Excel (Macros)
    http://www.excel-vba.com/excel-vba-contents.htm

    VBA Lesson 11: VBA Code General Tips and General Vocabulary
    http://www.excel-vba.com/vba-code-2-1-tips.htm

    Excel VBA -- Adding Code to a Workbook
    http://www.contextures.com/xlvba01.html

    Learn to debug:
    http://www.cpearson.com/excel/debug.htm

    How To: Assign a Macro to a Button or Shape
    http://peltiertech.com/WordPress/how...tton-or-shape/

    User Form Creation
    http://www.contextures.com/xlUserForm01.html

    When To Use a UserForm & What to Use a UserForm For
    http://www.ozgrid.com/Excel/free-tra...ba2lesson2.htm

    Excel Tutorials / Video Tutorials - Functions
    http://www.contextures.com/xlFunctions02.html

    INDEX MATCH - Excel Index Function and Excel Match Function
    http://www.contextures.com/xlFunctions03.html

    Excel Data Validation
    http://www.contextures.com/xlDataVal08.html#Larger
    http://www.contextures.com/excel-dat...ation-add.html

    Your Quick Reference to Microsoft Excel Solutions
    http://www.xl-central.com/index.html

    New! Excel Recorded Webinars
    http://www.datapigtechnologies.com/ExcelMain.htm

    Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
    This page describes how to write code that modifies or reads other VBA code.
    http://www.cpearson.com/Excel/vbe.aspx

    VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

    Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

    VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

    Excel 2007 Book: you can try this...there is a try before you buy ebook available at this link…

    by Stephen/ Bovey, Rob/ Green, John Bullen (Paperback - Feb 11, 2005)
    Professional Excel Development

    by Rob Bovey, Stephen Bullen, John Green, and Robert Rosenberg (Paperback - Sep 26, 2001)
    Excel 2002 VBA: Programmers Reference

    DonkeyOte: My Recommended Reading, Volatility
    http://www.decisionmodels.com/calcsecretsi.htm

    Sumproduct
    http://www.xldynamic.com/source/xld.SUMPRODUCT.html

    Arrays
    http://www.xtremevbtalk.com/showthread.php?t=296012

    Pivot Intro
    http://peltiertech.com/Excel/Pivots/pivotstart.htm

    Email from XL - VBA
    http://www.rondebruin.nl/sendmail.htm

    Outlook VBA
    http://www.outlookcode.com/article.aspx?ID=40

    Function Dictionary
    http://www.xlfdic.com/

    Function Translations
    http://www.piuha.fi/excel-function-name-translation/

    Dynamic Named Ranges
    http://www.contextures.com/xlNames01.html

    How to create Excel Dashboards
    http://www.contextures.com/excel-dashboards.html
    http://chandoo.org/wp/excel-dashboards/
    http://chandoo.org/wp/management-dashboards-excel/
    http://www.exceldashboardwidgets.com/
    http://www.andypope.info/charts/gauge.htm

    Excel Dashboard / Scorecard Ebook
    http://www.qimacros.com/excel-dashboard-scorecard.html

    Mike Alexander from Data Pig Technologies
    Excel 2007 Dashboards & Reports For Dummies

    Templates
    http://www.cpearson.com/Excel/Topic.aspx
    http://www.contextures.com/excel-tem...lf-scores.html

    Date & Time stamping:
    http://www.mcgimpsey.com/excel/timestamp.html

    Get Formula / Formats thru custom functions:
    http://dmcritchie.mvps.org/excel/formula.htm#GetFormat

    A nice informative MS article "Improving Performance in Excel 2007"
    http://msdn.microsoft.com/en-us/library/aa730921.aspx

    Progress Meters
    http://www.andypope.info/vba/pmeter.htm
    http://www.xcelfiles.com/ProgressBar.html

    And, as your skills increase, try answering posts on sites like:
    http://www.mrexcel.com
    http://www.excelforum.com
    http://www.ozgrid.com
    http://www.vbaexpress.com
    http://www.excelfox.com

  5. #5
    Registered User
    Join Date
    05-03-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro for transposing multiple columns into a single row

    This is great information, and the macro worked great! Thanks again for all of your help.

  6. #6
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro for transposing multiple columns into a single row

    BBExcelusr,

    Thanks for the feedback.

    You are very welcome. Glad I could help.

    Come back anytime.

  7. #7
    Registered User
    Join Date
    09-06-2012
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro for transposing multiple columns into a single row

    Stanley,

    This is close to what I'm looking for.

    For users outside our network, they'll need to transpose values from a selected column to a string of .csv values. Ideally, this just gets to the clipboard and then they can right-click and paste the entries into a text box.

    I've outlined the manual approach to the business user. It isn't that complex for end users to highlight, transpose, save as csv, open notepad file, copy, paste. However, that's painful and I want to make it simpler.

    Ideally, the end user can just highlight the column of interest. Then the Macro, when activated, finds the highlighted column, determines the bounds (total number of values), copies these, transposes them to a row in csv format and puts them on the clipboard.

    Then, the user just navigates to the SQL report, fires it up, puts the cursor in the input text box, etc.

    We're using Excel 2010. Any input on this?

    Thanks,

    Mike

  8. #8
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro for transposing multiple columns into a single row

    PostalMike,

    This is close to what I'm looking for.

    Please do not post your questions in threads started by others - - this is known as thread hijacking.

    Always start a new thread for your questions and, if you think it helps, provide a link to any other thread as a reference.

    Start a new thread for your question and be sure to give it a search friendly title that accurately describes your need.


    When you start a New Post, with an appropriate title, then send me a Private Message with a link to your post, and I will have a look.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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