well.. so my idea was to build a string of characters from the column headings with a conditional formula of omitting it if there was no particular product ordered, then split the string... so what if you use the same idea and build a 30 character string for each product that was ordered?
The first one would be:
IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,2,)=0,"",LEFT(Sheet1!$B$1&"- - - - - - - - - - - - - - - ",30)) where the - - - is actually 30 spaces..
the next column instead of Sheet1!$A$2:$I$4,2, would be Sheet1!$A$2:$I$4,3,
and the heading would from Sheet1!$C$1 instead of Sheet1!$B$1
You build this whole string together, then for the first column heading you take the first 30 characters and use a TRIM function to lose the extra spaces:
=TRIM(LEFT(IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,2,)=0,"",LEFT(Sheet1!$B$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,3,)=0,"",LEFT(Sheet1!$C$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,4,)=0,"",LEFT(Sheet1!$D$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,5,)=0,"",LEFT(Sheet1!$E$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,6,)=0,"",LEFT(Sheet1!$F$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,7,)=0,"",LEFT(Sheet1!$G$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,8,)=0,"",LEFT(Sheet1!$H$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,9,)=0,"",LEFT(Sheet1!$I$1&" ",30)),30))
for the next heading instead of using a LEFT(..., 30) you can use a MID(..., 31, 30) to start at character 31 and go another 30 spaces
=TRIM(MID(IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,2,)=0,"",LEFT(Sheet1!$B$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,3,)=0,"",LEFT(Sheet1!$C$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,4,)=0,"",LEFT(Sheet1!$D$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,5,)=0,"",LEFT(Sheet1!$E$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,6,)=0,"",LEFT(Sheet1!$F$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,7,)=0,"",LEFT(Sheet1!$G$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,8,)=0,"",LEFT(Sheet1!$H$1&" ",30))&IF(VLOOKUP($A2,Sheet1!$A$2:$I$4,9,)=0,"",LEFT(Sheet1!$I$1&" ",30)),31,30))
I apologize for the long formula.. if I ever messed up a formula and wrote something very long where it doesn't need to be, then this might be it...
Edit: I thought this was going to be an issue.. where I have 30 spaces, it shows only 1