+ Reply to Thread
Results 1 to 9 of 9

VBA Macro for Transposing Columns to Rows on Predetermined Format

  1. #1
    Registered User
    Join Date
    01-21-2015
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    4

    Smile VBA Macro for Transposing Columns to Rows on Predetermined Format

    Hi Everyone,

    I would appreciate your help with a Macro to transpose columns to rows based on a predetermined format. Essentially, I need to take the data from the “ Original” tab and convert it to the “Final” tab view. It’s just taking row data from “date” and “amount” and placing it next to each other in columns. Is there a quick function to do that?

    http://www.excelforum.com/excel-prog...ml#post3963983
    Attached Files Attached Files
    Last edited by dh507249; 01-22-2015 at 01:06 AM. Reason: More Descriptive Title

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Need Urgent Help with Macro - PLEASE

    Hello dh507249 and welcome to the forum,

    As per forum rules, please change the title of you thread to better describe your problem.http://www.excelforum.com/forum-rule...rum-rules.html

    Here's a code that should help you :

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Registered User
    Join Date
    01-21-2015
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    4

    Re: Need Urgent Help with Macro - PLEASE

    Thank you very much. This is exactly what I needed. I appreciate the immediate solution! Thanks again!

  4. #4
    Registered User
    Join Date
    01-21-2015
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA Macro for Transposing Columns to Rows on Predetermined Format

    Hello,

    I appreciate the help I received. The macro worked perfectly. I had another request to the same macro code. I would appreciate the additional assistance if at all possible.

    I’m wondering if it’s possible to add a few more column fields to the macro? They can be added wherever it’s easy. I’ve highlighted the additional fields in the attached file. Essentially, I would need to take the additional highlighted fields from the "Original_v2" tab and place them in the associated fields highlighted in tab "Final_v2". I've attached the revised test macro file with the newly added fields (highlighted)below.

    Test file_v4.xlsm

    Thank you,
    Darren

  5. #5
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: VBA Macro for Transposing Columns to Rows on Predetermined Format

    Hello Darren,

    Here's the update macro.
    I added some comments so you can understand the code.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    01-21-2015
    Location
    Los Angeles, CA
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA Macro for Transposing Columns to Rows on Predetermined Format

    Thanks again. Your comments are really helpful. I will be reviewing the code, but the macro works well.

  7. #7
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA Macro for Transposing Columns to Rows on Predetermined Format

    Hi GC Excel


    Quote Originally Posted by GC Excel View Post
    Hello …….. the update macro.
    I added some comments so you can understand………
    . I try to learn from lurking through codes such as yours and have to work very hard to understand them. I just wanted mainly to say how very grateful I am that you put explaining ‘green comments in. It makes a very big difference to how quickly I can benefit from these sorts of codes

    . Many Thanks

    Alan Elston

    P.s. Just a very minor point while I am here. I am simply trying in parallel to the Theory to also benefit from the experience of Profi’s like you….

    . With regard to “capturing” as it were the initial data in the first sheet in one go into an Array. I have gone to great length to get it clear in my head exactly how and why to do this. For example here:
    …(…
    http://www.excelforum.com/excel-new-...to-arrays.html
    …. )

    . Therefore I would have written this section of your code :

    Please Login or Register  to view this content.
    …… to something like


    Please Login or Register  to view this content.

    . I realize the results are identical as shown, for example, in the Watch Window.
    . My question is simply.

    . 1) As an experienced user you are relying on what I believe are called the “Implicit Defaults” (rather than defining “explicitly”) to give the correct outcome (That is to say an array of values rather than for example a Range Object) as you know that Excel will in this case “guess” correctly.

    Or

    . 2) In this case is there an extra reason for you doing it the way you have.

    . I apologies if it is comes across as very pedantic, I am simply trying to get a feel for actual practice by experienced users in parallel to the “Theory”

    . Thanks again

    Alan

  8. #8
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: VBA Macro for Transposing Columns to Rows on Predetermined Format

    Hi Doc.AElstein,

    When I pass a range to an array, I usually write :

    Please Login or Register  to view this content.
    For an array, I will rarely write the variable type (Variant), because I didn't "learn" it that way and by default if you don't declare a variable it will be Variant type.
    I will most of the time use .Value but in this specific case I reuse a old code that I took from someone else.

    Note:
    My coding is far from perfect. I learned by looking at codes written by others and over the years I have developped my own "coding" habits. (some good, some bad).
    You will probably end up doing the same over time...

  9. #9
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA Macro for Transposing Columns to Rows on Predetermined Format

    Hi GC Excel,

    Quote Originally Posted by GC Excel View Post
    .........
    When I pass a range to an array, I usually write :
    ..............
    ...... I learned by looking at codes..........
    ...

    ..... Many thanks for taking the time to come back for me to a Thread you had already solved very well.
    . Sorry if it came across as a bit trivial. I am sort of learning in “isolation” as it were stuck here in the Bavarian Hills. (I am learning excel VBA just to speed up a private but important project..) It makes therefore a big difference to me when trying to learn from codes to have an idea of typical practice or why something may differ from what I may have expected from the “Theory”.
    . As does good ‘green comments in Code. Many thanks again for taking the extra trouble to do that. I know from my early days in teaching how hard it can be sometimes when you have to try to explain to someone learning something which you yourself have long since learnt and as such find yourself somewhat obvious.
    . Thanks again for going that “extra bit” which sometimes makes a big difference to me “getting it”
    Alan.



    P.s.
    I do note that you choose
    ar = ws1.cells(1).CurrentRegion.Value
    and not
    ar() = ws1.cells(1).CurrentRegion.Value
    as I suggested.

    . This is an indication perhaps of the experienced way….: –
    . After some help from this Forum here
    http://www.excelforum.com/excel-new-...to-arrays.html
    I finally got the point of mine giving an error for on any occasion that only one cell was referenced. Yours would not produce a 1 dimensional Array in such a case, it would produce one value . But it would not error, which in the practice would probably be preferable, - so again result of experience I guess…..

+ 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. [URGENT][Help with a VBA Macro - Maximum with criterias][URGENT]
    By mahmoudmerhi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2013, 03:39 PM
  2. Need Urgent Help for this Macro
    By RizwanS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-05-2013, 05:36 AM
  3. Urgent Macro help
    By Yeshwin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-27-2005, 02:05 PM
  4. Urgent - Help VBA Macro
    By Jeff in forum Excel General
    Replies: 8
    Last Post: 10-03-2005, 04:05 PM
  5. [SOLVED] Urgent,! Need help with this Macro
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2005, 01:06 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