@SirJB7,
My apologies for the delayed response. Got back from a trip out of town... and catching up on posts.
Looks like Narayan posted an elegant solution for the problem.
My approach was a bit "quick and dirty"... but here it is:
I have assumed that the header is named as "PriceHeader" and the data is named as "Data", for ease of reference in the formulas.
My source data setup was as follows:
[pre]
Code:
3USD 4USD 5USD 6USD
BOOK EARRING NECKLACE BELT
BELT BOOK FLASH MEM BOOK
BELT
CAR NECKLACE EARRING BOOK
CAR CAR CAR CAR
(My test source data includes some blank cells.)
My result range was setup starting in cell H14
[pre][code]BOOK EARRING NECKLACE BELT FLASH MEM CAR
3USD 4USD 4USD 3USD 5USD 3USD
4USD 5USD 5USD 4USD #NUM! 4USD
6USD #NUM! #NUM! 6USD #NUM! 5USD
#NUM! #NUM! #NUM! #NUM! #NUM! 6USD
[/pre]
The header in the result set is calculated using the following formula (shown for cell H14)
=OFFSET($A$1, INT(MIN(IF( (Data<>"")*ISNA(MATCH(Data, $G$14:G$14,0)), ROW(Data) + COLUMN(Data)%)))-1, ROUND(MOD(MIN(IF( (Data<>"")*ISNA(MATCH(Data, $G$14:G$14,0)), ROW(Data) + COLUMN(Data)%)), 1)*100, 0)-1)
entered with Ctrl + Shift + Enter
The values in the result set is calculated using the following formula (shown for cell H15)
=INDEX(PriceHeader, SMALL(IF(ISNA(MATCH(IF(Data=H$14,COLUMN(Data)), IF(ISNUMBER(MATCH(PriceHeader, H$14:H14, 0)), COLUMN(PriceHeader)), 0)), IF(Data=H$14,COLUMN(Data))),1))
enter with Ctrl + Shift + Enter
Copy the formulas to additional cells. You could wrap it in an IFERROR to suppress the errors.
While writing this, I began to wonder what if I wanted the header to be sorted in alphabetical order.
So here is one approach to get a sorted header.
First the result set (for the same source data), setup starting in cell N3
BELT BOOK CAR EARRING FLASH MEM NECKLACE
3USD 3USD 3USD 4USD 5USD 4USD
4USD 4USD 4USD 5USD #NUM! 5USD
6USD 6USD 5USD #NUM! #NUM! #NUM!
#NUM! #NUM! 6USD #NUM! #NUM! #NUM![/code][/pre]
The sorted header row is calculated using the following formula (shown for cell N3)
=INDIRECT("R" & SUBSTITUTE(LARGE(IF(COUNTIF(Data,">"&Data)=LARGE(IF(COUNTIF($M$3:M3,"<"&Data)>=COUNTA($M$3:M3),COUNTIF(Data,">"&Data)),1),ROW(Data)+COLUMN(Data)%),1), ".","C"),FALSE)
enter with Ctrl + Shift + Enter
The values are calculated using the previous formula (this time shown for cell N4)
=INDEX(PriceHeader, SMALL(IF(ISNA(MATCH(IF(Data=N$3,COLUMN(Data)), IF(ISNUMBER(MATCH(PriceHeader, N$3:N3, 0)), COLUMN(PriceHeader)), 0)), IF(Data=N$3,COLUMN(Data))),1))
enter with Ctrl + Shift + Enter
Cheers,
Sajan.