Macro help to transpose data in stacked form

Fractalis

Active Member
Joined
Oct 11, 2011
Messages
310
Office Version
  1. 2019
Platform
  1. Windows
Hi all,

I
May someone help with with this.

I'd like to tabulate this stacked structure of parameters (column A) and values(column B) that has multiple blocks as shown below
in range A1:B3 in the way shown in D1:L14.

First block of data (first row to be tabulated), begins with "WORLD" and begins with "CAPITAL". Then could continue 0 o more blocks containing
only a few parameters, that begins with "COUNTRYCODE" and ends with "CAPITAL". Then could be others blocks that begins with "CONTINENT"
and ends with "PRM". Then could be others blocks that contains only "PRM".

Thee headers in output would be the unique parameters from column A, except "POLCODE" that is not needed to print in output. Each block that
begins with "WORLD" or "COUNTRYCODE" would be a new row in output. For "PRM" values extract the numbers after "ncc" and after "kng".

How to know if "COUNTRYCODE" belongs or not to a bigger block that begins with "WORLD"? Well, one row only could have the value of each
parameter. If one parameter appears again, should go in another row. The same applies to "PRM".

Thanks in advance for any help

COUNTRIES.xlsx
ABCDEFGHIJKL
1WORLD1WORLD CONTINENTCONTINENTNAMECONTINENTCODEGOVERNMENTCOUNTRYCODECOUNTRYCAPITALPRM
2CONTINENT111AMERICAAME01PRE55BRAZILBRASILIA
3CONTINENTNAMEAMERICA11AMERICAAME01PRE51PERULIMA
4CONTINENTCODEAME0111AMERICAAME01PRE1784SAINT_VINCENTKINGSTOWN
5GOVERNMENTPRE13EUROPEEUR03KNGD359BULGARIASOFIA
6COUNTRYCODE5513EUROPEEUR03KNGD36HUNGARYBUDAPEST
7COUNTRYBRAZIL2ASIAEXC35KNGD060-458
8CAPITALBRASILIA2ASIAEXC35KNGD392-392
9COUNTRYCODE515AFRICAEXC35PRE231-251
10COUNTRYPERU5AFRICAEXC35PRE324-224
11CAPITALLIMA5AFRICAEXC35PRE450-261
12COUNTRYCODE17845AFRICAEXC35PRE686-221
13COUNTRYSAINT_VINCENT5AFRICAEXC35PRE788-216
14CAPITALKINGSTOWN5AFRICAEXC35PRE148-235
15WORLD1
16CONTINENT3
17CONTINENTNAMEEUROPE
18CONTINENTCODEEUR03
19GOVERNMENTKNGD
20COUNTRYCODE359
21COUNTRYBULGARIA
22CAPITALSOFIA
23COUNTRYCODE36
24COUNTRYHUNGARY
25CAPITALBUDAPEST
26CONTINENT2
27CONTINENTNAMEASIA
28CONTINENTCODEEXC35
29GOVERNMENTKNGD
30POLCODEASIRPL2
31PRMkng.cc060.ncc458.svfdata
32PRMkng.cc392.ncc392.svfdata
33CONTINENT5
34CONTINENTNAMEAFRICA
35CONTINENTCODEEXC35
36GOVERNMENTPRE
37POLCODEAFRRPL5
38PRMpre.cc231.ncc251.svfdata
39PRMpre.cc324.ncc224.svfdata
40PRMpre.cc450.ncc261.svfdata
41PRMpre.cc686.ncc221.svfdata
42PRMpre.cc788.ncc216.svfdata
43PRMpre.cc148.ncc235.svfdata
Sheet7
 
I used in B2 a formula that is slightly different than yours:
Excel Formula:
=IFERROR(FILTERXML($A$1,"//COUNTRIES/group["&ROW(A1)&"]/"&B$1),"")

Excellent!!! It works better and without to insert an array formula like mine. I think the fill-down thing is not possible but only with a macro? or is do you still have some trick hidden? :)
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Done. Using Excel 2019
 
Upvote 0

Forum statistics

Threads
1,215,361
Messages
6,124,497
Members
449,166
Latest member
hokjock

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