您的位置:程序门 -> 其他开发语言 -> office开发/ vba



在excel中怎样完成这样的功能?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


在excel中怎样完成这样的功能?
发表于:2007-09-20 10:41:50 楼主
在excel中怎样完成这样的功能?

我有一张表数据,如图1所示,图中只有24项内容,但实际上可能是上100条内容,或者只有几条内容,并且一种物料可能都有几条记录,也许只有一条记录。
图1数据
项次 物   料   编   号 物   料   名   称 单位 数   量 单   价 金   额 交货日期
1 r2pp0003nc00 十字片 pcs 153 0.2 30.6 2007-9-19
2 r2pp0003nc00 十字片 pcs 612 0.2 122.4 2007-9-19
3 r2pp0003nc00 十字片 pcs 306 0.2 61.2 2007-10-24
4 r2pp0003nc00 十字片 pcs 408 0.2 81.6 2007-9-24
5 r2pp0003nc00 十字片 pcs 510 0.2 102 2007-9-20
6 r2pp0003nc00 十字片 pcs 258 0.2 51.6 2007-9-25
7 r2pp0003nc00 十字片 pcs 1023 0.2 204.6 2007-9-25
8 r2pp0003nc00 十字片 pcs 1224 0.2 244.8 2007-9-25
9 r2pp0003nc00 十字片 pcs 153 0.2 30.6 2007-10-6
10 r2pp0004nc00 长条支架     pcs 612 1.4 856.8 2007-9-19
11 r2pp0004nc00 长条支架                   pcs 153 1.4 214.2 2007-9-19
12 r2pp0004nc00 长条支架                   pcs 306 1.4 428.4 2007-10-24
13 r2pp0004nc00 长条支架           pcs 408 1.4 571.2 2007-9-24
14 r2pp0004nc00 长条支架                   pcs 510 1.4 714 2007-9-20
15 r2pp0004nc00 长条支架         pcs 258 1.4 361.2 2007-9-25
16 r2pp0004nc00 长条支架                   pcs 1023 1.4 1432.2 2007-9-25
17 r2pp0004nc00 长条支架                   pcs 1224 1.4 1713.6 2007-9-25
18 r2pp0004nc00 长条支架                   pcs 153 1.4 214.2 2007-10-6
19 r2pp0005gy00 转轮 pcs 0.08 1.1 0.09 2007-9-19
20 r2pp0005gy00 转轮 pcs 612 1.1 673.2 2007-9-19
21 r2pp0005gy00 转轮 pcs 153 1.1 168.3 2007-9-19
22 r2pp0005gy00 转轮 pcs 258 1.1 283.8 2007-9-25
23 r2pp0005gy00 转轮 pcs 1023 1.1 1125.3 2007-9-25
24 r2pp0005gy00 转轮 pcs 1224 1.1 1346.4 2007-9-25

现在目的:相得到图2结果,即在另一张表中,利用公式或者编程,以“物料编码”为汇总条件,生成一
条记录。
图2数据:
项次 物   料   编   号 物   料   名   称 单位 数   量 单   价 金   额 交货日期
1 r2pp0003nc00 十字片 pcs 4647 0.2 929.4 2007-9-19
2 r2pp0004nc00 长条支架                   pcs 4647 1.4 6505.8 2007-9-20
3 r2pp0005gy00 转轮 pcs 3270.08 1.1 3597.09 2007-9-19

要求:有相同物料编码时,物料编码只生成一个,名称也要求生成,数量要求汇总,单价要求平均值,金额可以汇总,也可以由“数量*单价”,日期取“最小(最早)日期”。
我的操作方法:利用“数据”菜单下的“分类汇总”功能,选择“物料编码”一项,但是汇总方式只能选择一种,要么求和,要么求平均值,不能要求达到该汇总时汇总,该平均值时平均值,该最小值时最小值,并且选择“物料名称”汇总时,出来的是“0”。
所以请问下有高手一下,这个表应该怎样快速自动生成呢。谢谢!!!!!
发表于:2007-09-20 13:47:031楼 得分:0
sub   statistics()
dim   ret   as   worksheet
dim   sr   as   integer
dim   prc   as   long
sr   =   0
prc   =   0
set   ret   =   worksheets("result")
with   worksheets("source")
for   ps   =   2   to   .usedrange.rows.count
        for   pr   =   1   to   ret.usedrange.rows.count
                if   .cells(ps,   2).value   =   ret.cells(pr,   2).value   then
                        ret.cells(pr,   3).value   =   .cells(ps,   3).value
                        ret.cells(pr,   4).value   =   .cells(ps,   4).value
                        ret.cells(pr,   5).value   =   .cells(ps,   5).value   +   ret.cells(pr,   5).value
                        ret.cells(pr,   6).value   =   (.cells(ps,   6).value   +   prc)   /   (sr   +   1)
                        ret.cells(pr,   7).value   =   .cells(ps,   7).value   +   ret.cells(pr,   7).value
                        if   ret.cells(pr,   8)   >   .cells(ps,   8)   then
                                ret.cells(pr,   8).value   =   .cells(ps,   8)
                        end   if
                        exit   for
                end   if
        next   pr
        if   pr   =   ret.usedrange.rows.count   +   1   then
                        for   i   =   2   to   8
                                ret.cells(pr,   i)   =   .cells(ps,   i)
                        next   i
        end   if
next   ps
end   with
end   sub
发表于:2007-09-21 16:11:242楼 得分:0
编程吧,没办法
发表于:2007-09-21 18:04:073楼 得分:0
mark
发表于:2007-09-22 09:03:564楼 得分:0

参考我另一个帖子...
http://community.csdn.net/expert/topic/5762/5762022.xml?temp=.1142084
发表于:2007-09-22 09:34:375楼 得分:0
用数据透视表,可以设置各个字段的统计汇总方式。


快速检索

最新资讯
热门点击