+ Reply to Thread
Results 1 to 10 of 10

Advanced transpose macro (VBA help)

  1. #1
    Registered User
    Join Date
    06-25-2013
    Location
    Asia
    MS-Off Ver
    Excel 2007
    Posts
    23

    Advanced transpose macro (VBA help)

    Hi,
    A couple of weeks ago I got help from a very kind person called "yudlugar" in this forum but not\w I need to modify his solution a bit. I cant seem to reopen the last thread so that is why I made a new one. Here is a link to the old one:http://www.excelforum.com/excel-prog...-vba-help.html


    Formula: copy to clipboard
    Please Login or Register  to view this content.


    What has happened is that I am adding rows to the data each month (right now up to ROW AE) and therefore the macro does not work any more. I have updated the code manually by changing the values highlighted in red above, but that is not very efficient, and also very complicated to explain to someone else how to do....

    Therefore, I was hoping that someone could show me how this can be done automatically. For example by counting how many of the cells in row 1 contains numbers, i guess it would be easy to do this, but I only know how to count in excel hehe and not VBA.

    For example now it is from A to AE = 31 rows... And from F (6) to AE (31) = 26

    Thanks a lot in advance!

    Kind Regards

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Advanced transpose macro (VBA help)

    Add this to your code
    Please Login or Register  to view this content.
    Change this line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Change this line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    I can't help with the 25 because I don't understand what that is doing or what you want there.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    06-25-2013
    Location
    Asia
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Advanced transpose macro (VBA help)

    Dear alan,
    Thanks a lot for your reply.

    I replaced what you suggested so it now looks like this.

    Please Login or Register  to view this content.
    Unfortunately however it does not work.

    Firstly when I change

    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    i get a message saying
    "Run-time error '1004':
    Application-defined or object-defined error"

    I know the lc works however and that it is 31 now...

    Secondly, I cant really explain why, but I need to be able to change the parts highlighted in blue and purple

    The blue one should always be lc - 6, which in the current situation is 25, and the purple one should always be lc - 5 (26 now)...

    Is this possible?

    Thanks in advance!

    Regards

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Advanced transpose macro (VBA help)

    Hi Nils,
    try it
    Please Login or Register  to view this content.

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Advanced transpose macro (VBA help)

    ... or this option
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-25-2013
    Location
    Asia
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Advanced transpose macro (VBA help)

    nilem,
    Thanks a lot for your help.
    Both of them works perfectly.

    The only difference I can see is that
    - "Macro_1" takes around 3 times as long as the "ertert" macro to perform the macro.
    - in order for "ertert" to work, I need to have a sheet in the workbook called "sheet2"
    - "ertert" turns all formating to "general" and therefore percentages etc. is converted to general...

    Why is ertert so much faster, and would it be possible to make it create a new sheet automatically instead of using sheet2?

    Once again thanks a lot, you have been truly great!

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Advanced transpose macro (VBA help)

    Nils,
    "ertert" takes only values​​, so we look at the data in a format General on sheet2. Just set the desired format for certain columns on sheet2 and then run the macro.
    "ertert" uses arrays, and it is much faster than copy-paste

  8. #8
    Registered User
    Join Date
    06-25-2013
    Location
    Asia
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Advanced transpose macro (VBA help)

    Thanks a lot!

  9. #9
    Registered User
    Join Date
    06-25-2013
    Location
    Asia
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Advanced transpose macro (VBA help)

    Hi Nilem,

    Actually I just found out that it does not work when I include all products. As it says in the excel doc that you also been working with, I actually have 10000+ rows of data, with more than 1000 products. For some reason not all these products are included in the macro output (only around 100 actually). can this be because some of these products are missing a lot of data, and that the code then does recognize that they are there and should be included? Column A to E are always filled 100% with data until the last product. But Columns F and above can be 100% empty or at least some cells can be empty for the products... I do not understand how this array using code works, so I cant modify it. could you please take a look at it again? I truly appreciate it!

    Regards
    Last edited by Nils88; 08-13-2013 at 05:41 AM.

  10. #10
    Registered User
    Join Date
    06-25-2013
    Location
    Asia
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Advanced transpose macro (VBA help)

    Hmm I think there is something wrong with my data, as I have found that sometimes there are 2 different product codes in the 11 rows of data for each product. This seems to be the problem with the macro, and by fixing the data the code will work. Thanks anyways!

+ 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] Advanced transpose macro (VBA help)
    By Nils88 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2013, 08:49 AM
  2. Advanced transpose macro
    By jlepard in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-24-2011, 10:31 PM
  3. Advanced Transpose
    By GavM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-21-2011, 10:05 AM
  4. Formatting (an advanced transpose)
    By two_tun in forum Excel General
    Replies: 3
    Last Post: 01-22-2011, 03:25 AM
  5. advanced transpose
    By eien kisu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-20-2008, 10:43 AM

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