Sort/transpose data based on one column

ialana

New Member
Joined
Nov 28, 2014
Messages
6
Hello. I need to put something like this:

NameCityCountryContinentDateCount
ABarcelonaSpainEurope01/01/2012613
ABarcelonaSpainEurope07/08/2012981
ABarcelonaSpainEurope05/03/20131205
ABarcelonaSpainEurope21/04/20152309
BLondonUKEurope03/02/20151
BLondonUKEurope23/12/20163267
CKyotoJapanAsia30/06/2014984
CKyotoJapanAsia02/01/20151267
CKyotoJapanAsia07/07/20152346
CKyotoJapanAsia23/03/20162687
CKyotoJapanAsia21/02/20173002

<colgroup><col><col><col><col><col span="2"></colgroup><tbody>
</tbody>

into something like this:

NameCityCountryContinentDate 1Count 1Date 2Count 2Date 3Count 3Date 4Count 4Date 5Count 5
ABarcelonaSpainEurope01/01/201261307/08/201298105/03/2013120521/04/20152309
BLondonUKEurope03/02/2015123/12/20163267
CKyotoJapanAsia30/06/201498402/01/2015126707/07/2015234623/03/2016268721/02/20173002

<colgroup><col><col><col><col><col span="10"></colgroup><tbody>
</tbody>

I know nothing about vba but have managed to copy/paste/get code working before.

Any help would be very much appreciated.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hello,

This is a bit tricky but I think I have it. Use Column K as the input for the other table. Rearrange your columns as I have shown so the count formula works:

REF

ABCDEFGHIJKLMNOPQRSTU
1CityCountryContinentNameDateCountCityCountryContinentNameDate 1Date 2Date 3Date 4Date 5Count 1Count 2Count 3Count 4Count 5
2BaSpEuA01/01/2012613BaSpEuA01/01/201208/07/201203/05/201321/04/201561398112052309
3BaSpEuA08/07/2012981LoUKEuB02/03/201523/12/201613267
4BaSpEuA03/05/20131205C
5BaSpEuA21/04/20152309D
6LoUKEuB02/03/20151E
7LoUKEuB23/12/20163267F
8G

<tbody>
</tbody>

Spreadsheet Formulas
CellFormula
H2{=IFERROR(INDEX(A$2:A$8,MATCH($K2,$D$2:$D$8,0)),"")}
I2{=IFERROR(INDEX(B$2:B$8,MATCH($K2,$D$2:$D$8,0)),"")}
J2{=IFERROR(INDEX(C$2:C$8,MATCH($K2,$D$2:$D$8,0)),"")}
L2{=IFERROR(INDEX($E$2:$E$8,SMALL(IF($D$2:$D$8=$K2,ROW($E$2:$E$8)-MIN(ROW($E$2:$E$8))+1),COLUMNS($K$2:K2))),"")}
M2{=IFERROR(INDEX($E$2:$E$8,SMALL(IF($D$2:$D$8=$K2,ROW($E$2:$E$8)-MIN(ROW($E$2:$E$8))+1),COLUMNS($K$2:L2))),"")}
N2{=IFERROR(INDEX($E$2:$E$8,SMALL(IF($D$2:$D$8=$K2,ROW($E$2:$E$8)-MIN(ROW($E$2:$E$8))+1),COLUMNS($K$2:M2))),"")}
O2{=IFERROR(INDEX($E$2:$E$8,SMALL(IF($D$2:$D$8=$K2,ROW($E$2:$E$8)-MIN(ROW($E$2:$E$8))+1),COLUMNS($K$2:N2))),"")}
P2{=IFERROR(INDEX($E$2:$E$8,SMALL(IF($D$2:$D$8=$K2,ROW($E$2:$E$8)-MIN(ROW($E$2:$E$8))+1),COLUMNS($K$2:O2))),"")}
Q2{=IFERROR(INDEX($F$2:$F$8,SMALL(IF($D$2:$D$8=$K2,ROW($F$2:$F$8)-MIN(ROW($F$2:$F$8))+1),COLUMNS($K$2:K2))),"")}
R2{=IFERROR(INDEX($F$2:$F$8,SMALL(IF($D$2:$D$8=$K2,ROW($F$2:$F$8)-MIN(ROW($F$2:$F$8))+1),COLUMNS($K$2:L2))),"")}
S2{=IFERROR(INDEX($F$2:$F$8,SMALL(IF($D$2:$D$8=$K2,ROW($F$2:$F$8)-MIN(ROW($F$2:$F$8))+1),COLUMNS($K$2:M2))),"")}
T2{=IFERROR(INDEX($F$2:$F$8,SMALL(IF($D$2:$D$8=$K2,ROW($F$2:$F$8)-MIN(ROW($F$2:$F$8))+1),COLUMNS($K$2:N2))),"")}
U2{=IFERROR(INDEX($F$2:$F$8,SMALL(IF($D$2:$D$8=$K2,ROW($F$2:$F$8)-MIN(ROW($F$2:$F$8))+1),COLUMNS($K$2:O2))),"")}

<tbody>
</tbody>
Formula Array:
Produce enclosing
{ } by entering
formula with CTRL+SHIFT+ENTER!

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Last edited by a moderator:
Upvote 0
Also Column K should be the only column to enter data in the other table. If there aren't any entries in this column then Column L will have 00/01/1900 and Column Q will have "0". Maybe someone can alter the formulas to take care of that issue.
 
Upvote 0
Thank you very much, BRS!

I've rearranged my table like you did, but unfortunately I'm only getting blank cells everywhere. Any ideas why?
 
Upvote 0
After you put the formula in Date 1 cell L2 in my example you need to press CTRL+SHIFT+ENTER to make it an array. Then drag across to the Date 5 cell then drag it down to bottom of range. Do the same for the count
 
Upvote 0
Also do the same for cell H2 and drag to J2 then down. The curly brackets at the beginning and end of the formulas mean they are arrays. Column K is the only column to enter the data. The rest will fill in from your data table.
 
Upvote 0
Still blank I'm afraid. This is what it looks like:

jhnpdFnn7PJD1kC_7BZlX0S1bt7f61lg0qa9dZrNDF14OtT1q9zgG2S6J8-Wz77m9JJA-Dua2LCZSzP-M8lzuMTlUSo8OrwVSAdFOJQlQC4EivYLnoKfncurv9HFsf9h3cdopEtRZH_MexLkj65UhBLpRgmR-mC5TUjEl7LePq_5QvPE-bKmUs69SvkkzD_-8gdr66RVyAwyOMs1mWJDJjyK3KSXptwbYG8DNDXmDm4kZUNESNi59gUe3QS5Vtq_aAfR3MQQdfNyEQ246zA8IvbaDFBol7D4w_Vfecq6RSKywe-qwa_L6vVkKBjmzYKjieBultU_ez51e0lKfaAo0rU5T5As9tQl1Selele_YA1DG7zMCI26voqB0g2Tjv9CIVex1kAlYb_Iede-gB8tr25DCnkkVZo6XzApqOCxupakKWcp2unU58A6bqoaz3ErQxL3freJOqef1jTIffr_nj5eSQTitqO0P2bJObgrn_72Ljl-y2_xB6ZM6wOAyfxtHXKkbDePTDe2dyU99GxgCWCCksfKC5QfBuOzBA6ZwMcaprIVjPtY3hb3K6kAnPOtDZ2V4f22gJWemg5I56h7sIbtfpmiVmKuTa26jZv6-i3WghDM_Q=w726-h432-no
 
Upvote 0

Forum statistics

Threads
1,214,535
Messages
6,120,093
Members
448,944
Latest member
SarahSomethingExcel100

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