Private Sub CommandButton1_Click()
Dim i%
For i = 2 To [b1]End(4)Row
With Sheet2
If ApplicationCountIfs([A:A], Cells(i, 2), [c:c], Cells(i, 1)) = 0 Then
[a65536]End(3)Offset(1) = Cells(i, 2)
[a65536]End(3)Offset(, 2) = Cells(i, 1)
[a65536]End(3)Offset(, 1) = Cells(i, 3)
Else
For j = 2 To [a65536]End(3)Row
If Cells(i, 2) = Cells(j, 1) And Cells(i, 1) = Cells(j, 3) Then
r = j
Exit For
End If
Next
Cells(r, 2) = Cells(r, 2) + Cells(i, 3)
End If
End With
Next
End Sub
备注:
上述代码是以07版本基础的,如果不支持,不能直接转换为03,需要重写。
Dim ThisTotal As Single
Dim i As Integer
ThisTotal = 0
For i = 1 To 4
ThisTotal = ThisTotal + ActiveSheetCells(i, 1)Value
Next i
For i = 1 To 4
ActiveSheetCells(i, 3)Value = ThisTotal
Next i
ThisTotal = 0
For i = 5 To 7
ThisTotal = ThisTotal + ActiveSheetCells(i, 1)Value
Next i
For i = 5 To 7
ActiveSheetCells(i, 3)Value = ThisTotal
Next i
ThisTotal = 0
For i = 8 To 10
ThisTotal = ThisTotal + ActiveSheetCells(i, 1)Value
Next i
For i = 8 To 10
ActiveSheetCells(i, 3)Value = ThisTotal
Next i
Sub 单票()
Dim x As Long
x = 3
With Sheet9
If IsNumber(TextBox1Value) Then
If TextBox1Value > 3 Then
x = TextBox1Value
End If
Else
TextBox1Value = 3
End If
Range("b7")Value = Sheet2Range("AA" & x)Value
Range("c7")Value = Sheet2Range("o" & x)Value
Range("d7")Value = Sheet2Range("n" & x)Value & "元"
Range("e7")Value = Sheet2Range("k" & x)Value & "KG"
Range("f7")Value = Sheet2Range("i" & x)Value & "件"
Range("g7")Value = Sheet2Range("q" & x)Value & "/" & Sheet2Range("z" & x)Value
TextBox1Value = TextBox1Value + 1
End With
End Sub
For Each c In Selection
If s + c - a <= 0 Then
s=s+c
else
exit for
end if
next
看见我加的两行了吗?else和exit for
If TargetAddress(0, 0) = "J12" Then改成比如
If TargetAddress(0, 0) = "J12" or TargetAddress(0, 0) = "K12" or TargetAddress(0, 0) = "L12" Then
或者说如果你要累加的单元格有什么规律那再根据实际情况处理了。
Function SM(v1 As Variant, v2 As Variant)
Dim v
For Each v In v1
SM = SM + v
Next v
SM = SM v2
End Function
复制代码到模块,然后点击任意单元格输入
=sm(选择你要求和区域,你要乘以的单元格)
以上就是关于怎么实现vba循环累加全部的内容,包括:怎么实现vba循环累加、Excel vba 求范围内累加并赋值最大那个、VBA循环累加复制的宏等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)