Converting rows to columns based on cell content

TimovieMan

New Member
Joined
Dec 17, 2015
Messages
6
Hi guys,

I have a long list of rows that needs to be converted based on one column's content. The list looks a bit like this:

Code:
Player | ID |  Game   | Score | Comment
-----------------------------------------
Anne   | 21 | Javelin | 41.2m | Drizzle, 16km/h headwind
Anne   | 21 | Javelin | 38.1m | Drizzle, 12km/h headwind
Anne   | 21 | Hurdle  | 18.7s | 12 km/h backwind
Anne   | 21 | HJump   | 1m54  | Drizzle
Bob    | 24 | Javelin | 55.1m | -
Bob    | 24 | Hurdle  | 15.4s | 10 km/h headwind
Bob    | 24 | HJump   | 1m72  | -
Bob    | 24 | HJump   | 1m76  | Winner
Colin  | 10 | Hurdle  | 13.0s | 10 km/h headwind, winner

Since there's only a limited number of games (I only gave three in the example but there are five), I want to cut back on the number of rows by dividing that into columns, so I get something like this:

Code:
Player | ID | Javelin Score | Javelin comment   | Hurdle score | Hurdle comment    | HJump score | HJump comment
-------------------------------------------------------------------------------------------------------------------
Anne   | 21 | 41.2m | Drizzle, 16 km/h headwind | 18.7s | 12 km/h backwind         | 1m54 | Drizzle
Anne   | 21 | 38.1m | Drizzle, 12 km/h headwind |       |                          |      |
Bob    | 24 | 55.1m | -                         | 15.4s | 10 km/h headwind         | 1m72 | -
Bob    | 24 |       |                           |       |                          | 1m76 | Winner
Colin  | 10 |       |                           | 13.0s | 10 km/h headwind, winner |      |

If there were only one possible option for each row, I could do this with VLOOKUP, but since several are possible and some might be blank, I have no idea how to approach this.

A pivot table got me close to what I needed, but it doesn't show the actual scores and comment, just the number of how many there are, so I'm guessing I'm going to need VBA to do this...
Anyone know an alternative way to do this (maybe with VLOOKUP or a pivot table workaround?), or can you help me out with the VBA code? My own VBA knowledge is pretty much limited to recording macro's...
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
This will probably sound silly and an insane workaround, but I managed to get the result I needed.

I first split all the data in separate worksheets (one for each game).
Then I used a pivot table on the original sheet to calculate the max number of scores and comments I would get for any one player, and created a list with just the players and their IDs, with as many duplicates as I would need in total.
Then I used an array formula I found here: https://www.mrexcel.com/forum/excel...up-return-2nd-matching-value.html#post3074838 (thanks, T. Valko!) to get all the n-th values I would need from each game worksheet.
And finally I deleted all the "#NUM!" values that were returned when no more data was available.

Massive workaround, perhaps, but it got the job done.
 
Upvote 0

Forum statistics

Threads
1,214,669
Messages
6,120,828
Members
448,990
Latest member
rohitsomani

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