将后 4 列有值格拆到不同的行
例题描述和简单分析
有Excel 文件 Book1.xlsx,sheet1 中数据如下所示:
A |
B |
C |
D |
E |
F |
|
1 |
Color |
Food |
1-Jan |
1-Feb |
1-Mar |
1-Apr |
2 |
Red |
Coke |
3 |
4 |
5 |
|
3 |
Purple |
Grapes |
6 |
3 |
7 |
|
4 |
Green |
Grapes |
1 |
1 |
1 |
|
5 |
Yellow |
Lemon |
2 |
3 |
||
6 |
Orange |
Orange |
1 |
2 |
||
7 |
Purple |
Grapes |
2 |
|||
8 |
Purple |
Grapes |
3 |
|||
9 |
Purple |
Grapes |
4 |
|||
10 |
Purple |
Grapes |
5 |
需要在sheet2 中,将后 4 列有值格拆到不同的行,结果如下:
A |
B |
C |
D |
|
1 |
Color |
Food |
Date |
Quantity |
2 |
Red |
Coke |
1-Jan |
3 |
3 |
Red |
Coke |
1-Feb |
4 |
4 |
Red |
Coke |
1-Mar |
5 |
5 |
Purple |
Grapes |
1-Feb |
6 |
6 |
Purple |
Grapes |
1-Mar |
3 |
7 |
Purple |
Grapes |
1-Apr |
7 |
8 |
Green |
Grapes |
1-Jan |
1 |
9 |
Green |
Grapes |
1-Feb |
1 |
10 |
Green |
Grapes |
1-Mar |
1 |
11 |
Yellow |
Lemon |
1-Mar |
2 |
12 |
Yellow |
Lemon |
1-Apr |
3 |
13 |
Orange |
Orange |
1-Jan |
1 |
14 |
Orange |
Orange |
1-Feb |
2 |
15 |
Purple |
Grapes |
1-Jan |
2 |
16 |
Purple |
Grapes |
1-Feb |
3 |
17 |
Purple |
Grapes |
1-Mar |
4 |
18 |
Purple |
Grapes |
1-Apr |
5 |
解法及简要说明
Excel 中加载插件 ExcelRaq.xll,加载宏文件 esproc_template.xla 后。
选中sheet2 的 A1 格,输入公式:=esproc("=?1.news(~.to(3:);?1.~(1):Color,?1.~(2):Food,?2(#):Date,~:Quantity).select(Quantity)",Sheet1!A2:F10,Sheet1!C1:F1),按下 ctrl+enter 后,删除第一行,即可实现需求。
英文版
英文版