|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
shengdingb 发表于 2014-2-11 23:08
不能用窗口里的 命令按钮控制吗?
可以用原来的,但需要在每个工作表代码区都写代码,而放到模块中仅需要写一个即可- Private Sub CommandButton1_Click()
- Dim arr, brr(), i&, j&, s$, r, m&, d As Object
- Set d = CreateObject("scripting.dictionary")
- arr = Sheets("出入库记录").Range("A1").CurrentRegion
- ReDim brr(1 To UBound(arr), 1 To 6)
- For i = 2 To UBound(arr)
- s = arr(i, 1) & vbTab & arr(i, 2)
- r = d(s)
- If r = "" Then
- m = m + 1
- d(s) = m
- r = m
- For j = 1 To 3
- brr(m, j) = arr(i, j)
- Next
- brr(m, 4) = arr(i, 6)
- End If
- If arr(i, 4) = "入库" Then
- brr(r, 5) = brr(r, 5) + arr(i, 5)
- ElseIf arr(i, 4) = "出库" Then
- brr(r, 6) = brr(r, 6) + arr(i, 5)
- End If
- Next
- For i = 1 To m
- brr(i, 6) = brr(i, 5) + brr(i, 6)
- Next
- With Sheets("库存")
- .Range("A1").CurrentRegion.Offset(1).ClearContents
- .Range("A2").Resize(m, 6) = brr
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|