|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
看的云里雾里的,不知道是不是这个意思:
- Sub test()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- r = [c2]
- arr = Range("e5:j" & r)
- ReDim brr(1 To UBound(arr), 1 To 6)
- For Each sht In Sheets
- If sht.Name <> ActiveSheet.Name Then
- With sht
- xm = .[i1]: n = .[c2]
- 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
- If m <= n Then
- For i = 2 To UBound(brr)
- If Len(brr(i, 1)) = 0 Then
- brr(i, 6) = ""
- Else
- brr(i, 6) = brr(i, 1) - brr(i - 1, 1)
- End If
- Next
- .Range("e5:i" & .Rows.Count).ClearContents
- .Range("e5").Resize(UBound(brr), UBound(brr, 2)) = brr
- Else
- For i = 2 To n
- If Len(brr(i, 1)) = 0 Then
- brr(i, 6) = ""
- Else
- brr(i, 6) = brr(i, 1) - brr(i - 1, 1)
- End If
- Next
- .Range("e5:i" & .Rows.Count).ClearContents
- .Range("e5").Resize(n, UBound(brr, 2)) = brr
- End If
- End With
- End If
- Next
- Application.ScreenUpdating = True
- MsgBox "数据计算完毕!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|