|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
依样画葫芦的事吧:
Sub 更新1007()
Application.ScreenUpdating = False
Set wk = ThisWorkbook
tms = Timer
r1 = [g1]: r2 = [h2].Value
If r2 <= r1 Then arr = Range("e5:j" & r1)
ReDim brr(1 To UBound(arr), 1 To 6)
Select Case [j1] * 1
Case "0"
f = False
For Each wb In Application.Workbooks
If wb.Name <> ThisWorkbook.Name And InStr(wb.Name, "三同") Then
f = True
With wb.Sheets(1)
xm = .[i1]: n = .[g1]
m = 0
For i = 1 To UBound(arr)
If arr(i, 6) = xm Then
m = m + 1: r = Application.Match(xm, wk.Sheets(1).[j:j], 0)
For j = 1 To 5
brr(m, j) = arr(i, j)
Next
End If
Next
For i = 1 To m
If i = 1 Then
brr(i, 6) = r - 4
Else
brr(i, 6) = brr(i, 1) - brr(i - 1, 1)
End If
Next
brr(m + 1, 6) = .[c1] - brr(m, 1)
.Range("e5:i" & n - 4).ClearContents
.Range("e5").Resize(n - 4, UBound(brr, 2)) = brr
End With
End If
Next
If f = False Then MsgBox "《 0 三同》" & "未打开!": Exit Sub
Case "1"
f = False
For Each wb In Application.Workbooks
If wb.Name <> ThisWorkbook.Name And InStr(wb.Name, "组三") Then
f = True
With wb.Sheets(1)
xm = .[i1]: n = .[g1]
m = 0
For i = 1 To UBound(arr)
If arr(i, 6) = xm Then
m = m + 1: r = Application.Match(xm, wk.Sheets(1).[j:j], 0)
For j = 1 To 5
brr(m, j) = arr(i, j)
Next
End If
Next
For i = 1 To m
If i = 1 Then
brr(i, 6) = r - 4
Else
brr(i, 6) = brr(i, 1) - brr(i - 1, 1)
End If
Next
brr(m + 1, 6) = .[c1] - brr(m, 1)
.Range("e5:i" & n - 4).ClearContents
.Range("e5").Resize(n - 4, UBound(brr, 2)) = brr
End With
End If
Next
If f = False Then MsgBox "《1 组三》" & "未打开!": Exit Sub
Case "2"
f = False
For Each wb In Application.Workbooks
If wb.Name <> ThisWorkbook.Name And InStr(wb.Name, "组六") Then
f = True
With wb.Sheets(1)
xm = .[i1]: n = .[g1]
m = 0
For i = 1 To UBound(arr)
If arr(i, 6) = xm Then
m = m + 1: r = Application.Match(xm, wk.Sheets(1).[j:j], 0)
For j = 1 To 5
brr(m, j) = arr(i, j)
Next
End If
Next
For i = 1 To m
If i = 1 Then
brr(i, 6) = r - 4
Else
brr(i, 6) = brr(i, 1) - brr(i - 1, 1)
End If
Next
brr(m + 1, 6) = .[c1] - brr(m, 1)
.Range("e5:i" & n - 4).ClearContents
.Range("e5").Resize(n - 4, UBound(brr, 2)) = brr
End With
End If
Next
If f = False Then MsgBox "《2 组六》" & "未打开!": Exit Sub
Case "3"
f = False
For Each wb In Application.Workbooks
If wb.Name <> ThisWorkbook.Name And InStr(wb.Name, "三同, 组三, 组六") Then
f = True
With wb.Sheets(1)
xm = .[i1]: n = .[g1]
m = 0
For i = 1 To UBound(arr)
If arr(i, 6) = xm Then
m = m + 1: r = Application.Match(xm, wk.Sheets(1).[j:j], 0)
For j = 1 To 5
brr(m, j) = arr(i, j)
Next
End If
Next
For i = 1 To m
If i = 1 Then
brr(i, 6) = r - 4
Else
brr(i, 6) = brr(i, 1) - brr(i - 1, 1)
End If
Next
brr(m + 1, 6) = .[c1] - brr(m, 1)
.Range("e5:i" & n - 4).ClearContents
.Range("e5").Resize(n - 4, UBound(brr, 2)) = brr
End With
End If
Next
If f = False Then MsgBox "所有分表均未打开!": Exit Sub
Case Else
Exit Sub
End Select
Application.ScreenUpdating = True
MsgBox "更新完成!,耗时" & Format(Timer - tms, "0.000s")
End Sub |
评分
-
1
查看全部评分
-
|