|
楼主 |
发表于 2024-4-8 09:44
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- function listDir(folderPath) {
- if (Dir(folderPath, jsDirectory) == "") throw new TypeError("参数错误,文件夹不存在")
- const results = []
- let file = Dir(folderPath + "/*")
- while (file != "") {
- results.push(folderPath + "\" + file)
- file = Dir()
- }
- return results
- }
- function test(){
- Application.ScreenUpdating=false
- var arr=listDir(ThisWorkbook.Path)
- var brr=[]
- var crr=[]
- const files = arr.filter(file => file!=ThisWorkbook.Path+"\\~$"+ThisWorkbook.Name && file!=ThisWorkbook.Path+"\"+ThisWorkbook.Name)
- files.forEach(file=>{
- var wb=Workbooks.Open(file);
- var sht=wb.Sheets("销售明细");
- brr=sht.Range("A2:J"+sht.Range("A65536").End(xlUp).Row).Value2;
- wb.Close(false);
- const br = brr.filter(b =>b[7]==Range("C1").Value2)
- crr=crr.concat(br)
- //debugger
- })
- Range("A3:J65536").ClearContents()
- Range("A3").Resize(crr.length,10).Value2=crr
- Application.ScreenUpdating=true
- }
- function flhz(){
- var arr = Sheets("客户明细").Range("A3:J"+Sheets("客户明细").Range("b65536").End(xlUp).Row).Value2
- var m=new Map();
- for (let b of arr){
- if (b[0]>=Range("b1").Value2 && b[0]<=Range("d1").Value2){
- if (m.has(b[8]+'|'+b[1])){
- m.set(b[8]+'|'+b[1],m.get(b[8]+'|'+b[1])+b[6]);
- }
- else{
- m.set(b[8]+'|'+b[1],b[6]);
- }
- }
- }
- var frr=[...m.entries()]
- Range("b3:d500").ClearContents();
- var sht=Worksheets('按送货地址单号');
- var j=0;
- for (let i=0;i<frr.length;i++){
- sht.Cells(i+3,2).Value2=frr[i][0].split("|")[0];
- sht.Cells(i+3,3).Value2=frr[i][0].split("|")[1];
- sht.Cells(i+3,4).Value2=frr[i][1];
- j=i;
- }
- Cells(j+4,4).Formula2="=sum(d3:d"+(j+3)+")"
- }
- function FC3(){
- var m=new Map();
- var i=Range("A65536").End(xlUp).Row;
- var arr=Range("A3:I"+i).Value2;
- arr.forEach(a=>{
- if (m.has(a[8])){
- m.get(a[8]).push(a);
- }
- else{
- m.set(a[8],[a]);
- }
- })
- var brr=[...m.keys()];
- brr.map(v=>{
- m.get(v).unshift(["日期","单据编号","商品全称","单位","数量","单价","金额","客户名称","送货地址"]);
- Sheets.Add(undefined,Sheets(Sheets.Count)).Range("A1").Resize(m.get(v).length,9).Value2=m.get(v);
- Columns.Item("A:A").NumberFormatLocal = "yyyy-m-d;@";
- Columns.Item("A:D").AutoFit();
- ActiveSheet.Name=v;
- })
- Sheets("客户明细").Visible=false;
- }
复制代码 |
|