VBA: flat table and put the results in a 2D table.

jbesclapez

Active Member
Joined
Feb 6, 2010
Messages
275
Hello there,
Hi Mick, Fluff and Rick ;)

I need help on a VBA code that could read a flat table and put the results in a 2D table.

The 2D Tables has in rows a list of Animals that is always in the Flat Tables. (no more no less).
The 2D Tables is NOT generated, it is the base where the flat table will put its values.
The column in the 2D Table has known attributes. (here it is legs, eyes, hairs...)
I would like the macro to read the Flat Table to put the value in the 2D Table.

The Flat Table is on one sheet and the Result table on another sheet.
The FlatTable starts on row 1 with a header
The FlatTable start on row 13 with a header

Please note that the amount of animals can change and be more or less.
Note, that the number of attributes can change but are always read from the 2D Table (now I have 4 attributes but i might add a new one)
Note I added in the table the colunms LMNOP for the flat table as it starts there and for the row it is 13 in the 2D Table

Flat Table from origin

LMNOP
1ANIMALAttributeData
2doglegsyes
3dogeyesno
4doghairswhy
5catlegsbut
6cateyesyes
7birdlegsno
8mouselegsyes
9mouseeyesno
10mousehairsno
11mousestomachyes

<tbody>
</tbody>


Result in 2D table

ABCDE
13ANIMALlegseyeshairsstomach
14dogyesnowhy
15catbutyes6
16birdno
17mouseyesnonoyes

<tbody>
</tbody>


If someone find the time to write this VBA, please comment it. I am also here to learn and I need to be able to understand it. I am not a total beginner but I have problems with complicated loops.


Thanks for your time
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
What about without VBA or formulas - a query table.
Such as via menu ALT-D-D-N, though there are other ways in newer versions.
Suggest giving the data a simple defined name and then saving the file before starting.
Follow wizard to end and take option to edit in MS Query. Use SQL as below. HTH

Code:
TRANSFORM MAX(Data)
SELECT ANIMAL
FROM YourTableName
GROUP BY ANIMAL
PIVOT Attribute
 
Upvote 0
What about without VBA or formulas - a query table.
Such as via menu ALT-D-D-N, though there are other ways in newer versions.
Suggest giving the data a simple defined name and then saving the file before starting.
Follow wizard to end and take option to edit in MS Query. Use SQL as below. HTH

Code:
TRANSFORM MAX(Data)
SELECT ANIMAL
FROM YourTableName
GROUP BY ANIMAL
PIVOT Attribute


Hi Fazza,
Thanks for having a look at this.
I need VBA for this. I can read and usually understand it. But my level is not as high as the one of pure developers.
Thanks
 
Upvote 0
Once you've set up the query, VBA can be

ThisWorkbook.RefreshAll
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,217
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top