Hi there,
I hope you guys can help me here - i would like to normalise and stack the following data:
table 1.jpg
to this format using vba:
table2.jpg
I'm not so familiar with vba/programming but I would like to learn. thanks so much..
Hi there,
I hope you guys can help me here - i would like to normalise and stack the following data:
table 1.jpg
to this format using vba:
table2.jpg
I'm not so familiar with vba/programming but I would like to learn. thanks so much..
Hi yching,
After many questions similar to this, where people wanted to convert Crosstab style table to better formatted Excel tables, I wrote some generalized code. It will convert Crosstab tables but you present a newer problem. The merged cells above the table showing year present a real problem. If you can remove those and make them like my sheet2 I can do the rest. See the attached.
One test is worth a thousand opinions.
Click the * Add Reputation below to say thanks.
Thanks MarvinP.
I still have a few questions here - If I have the following table, do I still have to change the structure of my table to match exactly like yours before running the macro?
2010 2010 2010 2011 2011 2011
Name A B C A B C
John 1 4 7 10 12 15
Alan 2 5 8 11 13 16
Bryan 3 6 9 11 14 17
Also, why must I enter fixed column=2?
Thanks![]()
Hi,
The way my macro works is this. I assume row 1 has the headers that go with the columns that need repeating. In the normal Crosstab table there are names down the rows and dates across the top in row 1. Sometimes there are two or three columns that are needed to repeat. The reason the macro stops and asks is to allow the user to tell how many columns are "fixed" and need repeating.
By reformatting your data and having the first column of Name and the second of Year it then fit the format my macro could deal with. I haven't seen many tables like yours where you have two levels of column headings. Maybe if this was a standard, I'd add a second input box to my macro and deal with your structure also.
In most Excel problems the work gets a lot harder if merged cells are involved. By repeating your 2010 and 2011 like you suggest above might help but still doesn't fit the format that my macro expects to deal with.
I hope this explains more of what my macro does and why I need it like Sheet2. If not, keep asking. If you get lots of data in the exact format you suggested in post 1 then I might try to improve my code to fit your problem. Let me know.
Hi MarvinP,
Thanks so much for your answer. I kind of understand what each step is doing by pressing F8.
Yes my table structure is a bit complex, my real data actually has 3 level of column headings and another 3 level of row headings.
I have been cracking my head but still no clue about how to solve this. So far I'm only manage to unpivot my data if it is a 1 level of column heading and 1 level of row heading..![]()
Give me an example of what your real data looks like and I'll scratch my head a bit to see if my code can deal with your problem.
You can attach a sample file by clicking on "Go Advanced" and then the Paper Clip Icon above the advanced message area.
Sample_Needs_To_Unpivot.xlsx
I have attached a sample here.
It's not the real data but it has the same structure and format.
The numbers in the sample are not correct as I randomly generated them but it shouldn't cause any problem.
Thanks a lot.
OK yching here you go,
I've added two subs to do your sheets. The first merges the column headers together into a single cell. The second fills in the blanks in column A.
To test it copy your Sheet1 data (all cells) to a new sheet. Then run the macro called "DoItAll". You need to tell the macro there are 3 fixed columns in your data.
If you want to put a new column in the converted table of Year, I'd suggest using a formula of =Right(D2,4) and fill it down.
I'm off to bed now in Seattle time. I hope this works for you. Remember to click the "Add Reputation" star below this post for all the work I may have saved you.
Thanks MarvinP,
I gave you a reputation point from another post (hope that helps?) as I wasn't able to find the "Add Reputation" button from my post.
Anyways night and thanks so much![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks