|
JSA代码,供参考
- function 合并(){
- let res=[...Sheets].reduce((res,sh)=>{
- if (sh.Name.search(/第.期/)==-1) return res;
- let [r1,r2]=[sh.Cells.Find("序号").Offset(2,0).Row,sh.Cells.Find("合计").Offset(-1,0).Row];
- let arr=sh.Range(`a${r1}:f${r2}`).Value2;
- arr.forEach(x=>{
- if (x[1]==null) return;
- [x[0],x[5]]=[sh.Name,"=SUM(RC[-2]:RC[-1])"];
- res.push(x);
- });
- return res;
- },[]);
- let app=Application;
- [app.DisplayAlerts,app.ScreenUpdating]=[false,false];
- try{Sheets.Item("合并").Delete()}catch{};
- Sheets.Item("合并模版").Copy(Sheets.Item("合并模版"));
- ActiveSheet.Name="合并";
- if (res.length>2) Range("a6").Resize(res.length-2,1).EntireRow.Insert();
- Range("a5").Resize(res.length,res[0].length).FormulaR1C1=res;
- [app.DisplayAlerts,app.ScreenUpdating]=[true,true];
- }
复制代码 |
|