VBA to unpivot a Fixed number of columns just like Power QUery

  • Hi dears!

    my first time posting here and also fairly new to macro coding. Found out this Forum is very helpful for beginners like me so i am very excited to be helped by you guys! ^^


    i've been searching high and low about this code that i need to do but sadly , although some are close, it doesn't actually do what i need which is in fact just the very simple scenario.


    I have 130 columns for example, and 13 of those columns has to be Unpivoted. That simple.

    Number of rows may of course vary from time to time.


    This works perfectly fine with Power Query but silly of me, vba doesn't do power query. lol 8o


    i have attached a sample file which may show how my data is being presented,

    where columns A to E are the fixed array, and F onwards will be the columns subject for unpivotting.


    Hope someone can really help me on this as i feel like my hairs are loosing now. lol.

    Thank you so much in advance!

    Let me know how i can repay your kindness.

  • Quicker and easier in PQ, but here is some code for you.


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!