Excel复制行取决于列值

在我的excel文件中,在第一列ProductName ,我有我的产品列表,每个产品列表可以有不同的尺寸: VerySmallSmallLarge等。每个Size都有自己的产品价格。 我试图垂直列出每个产品的可用尺寸和相应的价格。
这是原始的数据结构:

当前可用的Excel文件:

这就是我的结果

如何Excel文件将转换后:

我有大约8000+这样的产品。 这几天我试图find解决这个问题的办法,但是我完全失败了。 有没有办法拉大小和价格,并垂直列出?

假设数据在Sheet1和Sheet2是空的,写下这个代码作为一个VBAmacros(ALT + F11)并运行它(F5)

 Sub Flatten() Dim row as Integer,col as Integer, dst_row as Integer,dst_col as Integer Dim col_start as Integer,col_end as Integer 'Your parameters: col_start=3'C column col_end=12'L column row=2'Data starts from second row dst_row=row 'Copy the headers For col=1 To col_start+2 Sheet2.Cells(1,col)=Sheet1.Cells(1,col) Next col 'Flat the Table While Sheet1.Cells(row,col_start)<>"" For col=col_start To col_end Step 2 If Sheet1.Cells(row,col)<>"" Then For dst_col=1 To col_start Sheet2.Cells(dst_row,dst_col)=Sheet1.Cells(row,dst_col) Next dst_col Sheet2.Cells(dst_row,col_start)=Sheet1.Cells(row,col) Sheet2.Cells(dst_row,col_start+1)=Sheet1.Cells(row,col+1) dst_row=dst_row+1 End If Next col row=row+1 dst_row=dst_row+1 Wend End Sub