|
对图猜一个,能否运行就看你自己了。
- sub get_mon_6() '求出近6个月使用量
- dim arr,brr,i%,j%,my_month,my_year,my_y_m$
- dim sh as worksheet,dic as object,key$
- Set dic = CreateObject("Scripting.Dictionary")
- my_year=year(now) '得出现在的年份
- my_month=month(now) '得出现在的月份
- for i=1 to 6
- If my_month - i < 1 Then
- my_year = my_year - 1
- my_month = my_month + 12
- End If
- my_y_m = my_y_m & "," & my_year & my_month - i '得出符合年月的字符串
- next i
- set sh=sheets("生产领料序时簿")
- with sh
- brr=.usedrange
- for i=2 to ubound(brr)
- key=year(brr(i,3)) & month(brr(i,3))
- if instr(my_y_m$,key)>0 then '当日期的月份在近6个月之内
- if not dic.exists(brr(i,7)) then
- dic(brr(i,7))=brr(i,11)
- else
- dic(brr(i,7))=dic(brr(i,7))+brr(i,11) '合计求和
- end if
- end if
- next i
- end with
- set sh=sheets("采购计划表(续订业务)")
- with sh
- arr=.usedrange
- for i=2 to ubound(arr)
- if len(arr(i,1))>0 then .cells(i,8)=dic(arr(i,1)) '以物料长代码查找,速度要快些
- next i
- end with
- end if
复制代码 |
|