关于VBA求和
具体情况是这样的:A1A2A3A4A5A6A7A8B9B10B11B12B13C14C15C16C17C18C19C20C21C22。。。。。。在EXCEL的第一列,有A...
具体情况是这样的:
A 1
A 2
A 3
A 4
A 5
A 6
A 7
A 8
B 9
B 10
B 11
B 12
B 13
C 14
C 15
C 16
C 17
C 18
C 19
C 20
C 21
C 22
。。。。。。
在EXCEL的第一列,有A,B,C。。。。好多组,第二列是对应的数字,现在要分别对A,B,C。。。。等好多行,分组求和。如果数据量较少,可以用筛选功能手动地求和,可是现在数据有几十万行,手动求和不现实。。。 如果数据量大,但是每组的步长是一样的,可以写个简单的循环便能实现。但是现在,问题就在于,数据量大,而且,每组的步长是不一样的。。。。请教各位高手,谁能写个VBA循环,一次性地分组求和?不胜感激~~~ 展开
A 1
A 2
A 3
A 4
A 5
A 6
A 7
A 8
B 9
B 10
B 11
B 12
B 13
C 14
C 15
C 16
C 17
C 18
C 19
C 20
C 21
C 22
。。。。。。
在EXCEL的第一列,有A,B,C。。。。好多组,第二列是对应的数字,现在要分别对A,B,C。。。。等好多行,分组求和。如果数据量较少,可以用筛选功能手动地求和,可是现在数据有几十万行,手动求和不现实。。。 如果数据量大,但是每组的步长是一样的,可以写个简单的循环便能实现。但是现在,问题就在于,数据量大,而且,每组的步长是不一样的。。。。请教各位高手,谁能写个VBA循环,一次性地分组求和?不胜感激~~~ 展开
2个回答
展开全部
兄弟,这个用字典是非常好解决的呀
如你的数据在A、B列,汇总到D、E列,D列为不重复的名称,E列为对应汇总数量。数据都从第二行开始写入(第一行为标题)。在当前表中运行以下宏即得
Sub aa()
Dim d As Object, x&, arr
Set d = CreateObject("scripting.dictionary")
arr = Range("A2:B" & Range("A65536").End(xlUp).Row)
For x = 1 To UBound(arr)
d(arr(x, 1)) = d(arr(x, 1)) + arr(x, 2)
Next x
Range("D2").Resize(d.Count, 1) = Application.Transpose(d.keys)
Range("E2").Resize(d.Count, 1) = Application.Transpose(d.items)
End Sub
如你的数据在A、B列,汇总到D、E列,D列为不重复的名称,E列为对应汇总数量。数据都从第二行开始写入(第一行为标题)。在当前表中运行以下宏即得
Sub aa()
Dim d As Object, x&, arr
Set d = CreateObject("scripting.dictionary")
arr = Range("A2:B" & Range("A65536").End(xlUp).Row)
For x = 1 To UBound(arr)
d(arr(x, 1)) = d(arr(x, 1)) + arr(x, 2)
Next x
Range("D2").Resize(d.Count, 1) = Application.Transpose(d.keys)
Range("E2").Resize(d.Count, 1) = Application.Transpose(d.items)
End Sub
展开全部
Public Sub sum100do()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do While i <= 100
sum1 = sum1 + i
i = i + 1
Loop
MsgBox sum1
End Sub
Public Sub sum100doUT()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do Until i > 100
sum1 = sum1 + i
i = i + 1
Loop
MsgBox sum1
End Sub
Public Sub sum100doLW()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do
sum1 = sum1 + i
i = i + 1
Loop While i <= 100
MsgBox sum1
End Sub
Public Sub sum100doLU()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do
sum1 = sum1 + i
i = i + 1
Loop Until i > 100
MsgBox sum1
End Sub
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do While i <= 100
sum1 = sum1 + i
i = i + 1
Loop
MsgBox sum1
End Sub
Public Sub sum100doUT()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do Until i > 100
sum1 = sum1 + i
i = i + 1
Loop
MsgBox sum1
End Sub
Public Sub sum100doLW()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do
sum1 = sum1 + i
i = i + 1
Loop While i <= 100
MsgBox sum1
End Sub
Public Sub sum100doLU()
Dim i, sum1 As Integer
sum1 = 0
i = 1
Do
sum1 = sum1 + i
i = i + 1
Loop Until i > 100
MsgBox sum1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询