当前位置:编程学习 > VB >>

Excel VBA编程

跪求Excel vba的分类求和代码. --------------------编程问答-------------------- 放上数据格式看看。 --------------------编程问答-------------------- QQ群 48866293 OFFICE应用挖掘 
MS OFFICE(ACCESS\EXCE\WORD等应用技术探讨与交流!技术群,请阅群论坛中的《踢人规则》

问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
     --------------------编程问答-------------------- 2楼的图很好!!! --------------------编程问答-------------------- 2楼的图很好!!! --------------------编程问答-------------------- 图做的真的号 --------------------编程问答-------------------- 把分类名称放在A列,数值放在B列,执行程序后,C/D列会产生新的数据

Sub mysub()
Dim start As Double
start = Timer
Columns(3) = ""
Columns(4) = ""
Application.ScreenUpdating = False

Dim beginrow As Integer: beginrow = 1
Dim endrow As Long: endrow = Cells(Rows.Count, 1).End(xlUp).Row
Dim sumvalue As Long
Dim duibizhi As String

Dim k: k = 1

    For i = beginrow To endrow
        sumvalue = 0
        If Cells(i, 1) <> "" And Cells(i, 2) > 0 Then
            If Application.WorksheetFunction.CountIf(Columns(1), Cells(i, 1)) > 1 Then '---判断 是否重复
                duibizhi = Cells(i, 1)
                
                For j = i To endrow          '----重复值SUM
                    If Cells(j, 1) = duibizhi Then
                    'MsgBox i
                        sumvalue = sumvalue + Cells(j, 1).Offset(0, 1)
                   
                       Cells(j, 1).Value = ""
                       Cells(j, 1).Offset(0, 1).Value = ""
               
                    End If
                Next j
                
             Else
                duibizhi = Cells(i, 1)
                sumvalue = Cells(i, 1).Offset(0, 1)
                Cells(i, 1).Value = ""
                Cells(i, 1).Offset(0, 1).Value = ""
            End If
              
            If sumvalue > 0 Then             '-------生成新列
              Cells(k, 3).Value = duibizhi
              Cells(k, 4).Value = sumvalue
              k = k + 1
            End If
        End If
     Next i
        
        
               
Application.ScreenUpdating = True
 MsgBox "程序共执行了" & Timer - start & "秒!"
End Sub
--------------------编程问答-------------------- xuexi...........6L --------------------编程问答-------------------- 2楼正解啊 呵呵 --------------------编程问答-------------------- 楼主,你说的分类求和要实现一个什么样的功能?我现在就用着一个自己写的分类求和函数,其中有几个参数,第一个是求和区域,二是分类标记所在区域,三是分类标记,四是求和单元格与标记列的差,五是求和单元格的间隔(列差)
--------------------编程问答-------------------- 我也学习啦! --------------------编程问答-------------------- 学习了——问题问得太抽象!
补充:VB ,  VBA
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,