创建"展平"多个列表中的数据标签列

时间:2017-09-06 15:52:20

标签: excel vba excel-vba excel-formula

我想创建一个" flattened" Excel中的数据结构,用于列出属性的多个数据标签。例如:

我有以下数据列表:

Date     Department  Forecast Period
Jan-16   Marketing    2015 Nov
Feb-16   Accounting   2015 Dec
Mar-16   HR 
Apr-16      

我想将上述内容转换为以下数据结构:

Date    Department  Forecast Period
Jan-16  Marketing   2015 Nov
Jan-16  Marketing   2015 Dec
Jan-16  Accounting  2015 Nov
Jan-16  Accounting  2015 Dec
Jan-16  HR          2015 Nov
Jan-16  HR          2015 Dec
Feb-16  Marketing   2015 Nov
Feb-16  Marketing   2015 Dec
Feb-16  Accounting  2015 Nov
Feb-16  Accounting  2015 Dec
Feb-16  HR          2015 Nov
Feb-16  HR          2015 Dec
Mar-16  Marketing   2015 Nov
Mar-16  Marketing   2015 Dec
Mar-16  Accounting  2015 Nov
Mar-16  Accounting  2015 Dec
Mar-16  HR          2015 Nov
Mar-16  HR          2015 Dec
Apr-16  Marketing   2015 Nov
Apr-16  Marketing   2015 Dec
Apr-16  Accounting  2015 Nov
Apr-16  Accounting  2015 Dec
Apr-16  HR          2015 Nov
Apr-16  HR          2015 Dec

理想情况下,我还可以在前三个列表中添加/删除项目,并且转换后的数据会相应调整。我不确定VBA或公式是否是解决这个问题的最佳方式,但希望你能给我一些指导。

1 个答案:

答案 0 :(得分:1)

三个公式:

=IFERROR(INDEX($A$1:INDEX(A:A,MATCH(1E+99,A:A)),INT((ROW(1:1)-1)/((COUNTA(B:B)-1)*(COUNTA(C:C)-1)))+2),"")

=IF(E2<>"",INDEX(B:B,MOD(INT((ROW(1:1)-1)/(COUNTA(C:C)-1)),COUNTA(B:B)-1)+2),"")

=IF(E2<>"",INDEX(C:C,MOD((ROW(1:1)-1),COUNTA(C:C)-1)+2),"")

enter image description here