|
楼主 |
发表于 2018-5-20 22:42
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
非常感谢老师的帮助!我已用您6楼修改的代码测试过,计算结果正确、快捷!8楼的代码和6楼前后顺序不大相同【见红色部分】,哪个更好些?
Sub test()
Dim r&, i&, c&, j&
Dim arr, brr
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Worksheets("总表")
r = .Cells(.Rows.Count, 5).End(xlUp).Row
arr = .Range("e5:j" & r)
End With
With ActiveSheet
xm = .Range("i1")
End With
ReDim brr(1 To UBound(arr), 1 To 6)
m = 0
For i = 1 To UBound(arr)
If arr(i, 6) = xm Then
m = m + 1
For j = 1 To 5
brr(m, j) = arr(i, j)
Next
End If
Next
For i = 2 To UBound(brr)
If brr(i, 1) = 0 Or brr(i, 1) = "" Then
brr(i, 6) = Range("d1") - brr(i - 1, 1)
Exit For
End If
brr(i, 6) = brr(i, 1) - brr(i - 1, 1)
Next
With ActiveSheet
.Range("e5:i" & .Rows.Count).ClearContents
.Range("e5").Resize(UBound(brr), UBound(brr, 2)) = brr
End With
Application.ScreenUpdating = True
MsgBox "数据计算完毕!"
End Sub
另外,能不能把0、1、2里的三个按钮合并成一个,在总表里点击一次,则0、1、2工作表的数据就会自动更新?
|
|