|
本帖最后由 znppnz 于 2024-8-13 19:53 编辑
如题,我在学习JS宏从入门到放弃教程-JSA的3-27将数据拆分到不同工作表时,虽然是我自己的实例,但也非常仔细对比老师的讲解,修改多次,感觉没写错代码。但是始终无法全部循环,只拆分了一部分数据。请大神们帮我仔细查看一下,看问题出在哪里?
- function 总表拆分(){
- let wb=Workbooks.Item("总表拆分.xlsm" );
- let wbNew=Workbooks.Add();
- for (let strWsName of ["八1班","八2班","八3班","八4班","八5班","八6班","八7班","八8班"]){
- let wsNew=wbNew.Sheets.Add();
- wsNew.Name=strWsName;
- wsNew.Range("a1:k1").Value2=["姓名","语文","数学","英语","物理","生物","地理","道法与法治","历史","总分","班级"];
- }
- //直接选中相应单元格,按F9,出现{"姓名","语文","数学","英语","物理","生物","地理","道法与法治","历史","总分","班级"}这样的
- let rngBooks=wb.Sheets(1).Range("k2",wb.Sheets(1).Range("k65536").End(xlUp));
- for (let rngCell of rngBooks){
- rngCell.EntireRow.Range("a1:k1").Copy(wbNew.Sheets(rngCell.Value()).Range("A65536").End(xlUp).Offset(1,0));
- }
- wbNew.Sheets("Sheet1").Delete();
- wbNew.SaveAs(wb.Path + "\\结果.xlsx");
- wbNew.Close();
- }
复制代码
|
|