function test(){var dicGao=new Map();var dicDi=new Map();for(var i=2;i<9;i++){var dateTime=ActiveSheet.Range("A"+i).Value()if(true){var banji=ActiveSheet.Range("E"+i).Value()var ban=banji.split('-')[0]var duan=ban.charAt(0)var koufen=ActiveSheet.Range("F"+i).Value()if(duan>3){if(dicGao.has(ban)){dicGao.set(ban,dicGao.get(ban)+koufen)}else{dicGao.set(ban,koufen)}}else{if(dicDi.has(ban)){dicDi.set(ban,dicDi.get(ban)+koufen)}else{dicDi.set(ban,koufen)}}}}var tss=dicDi.get("11")Worksheets("各班汇总").Range("C9").Value2=dicDi.get("11")Worksheets("各班汇总").Range("D9").Value2=dicDi.get("12")//Range("J1").Resize(dicDi.size,2).Value2=[...dicDi]}
代码写好后,我们插入一个按钮,并点击右键指定宏为刚才我们编写的函数,编辑按钮上面的文本为“一键汇总”最后另存为.xlsm格式即可最终效果(图片来源网络,侵删)
0 评论