|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 更新分表()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long, rs As Long
Dim br()
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
For Each sh In Sheets
dc(sh.Name) = ""
Next sh
With Sheets("工商银行")
r = .Cells(Rows.Count, 6).End(xlUp).Row
If r < 13 Then MsgBox "数据源为空!": End
ar = .Range("e11:p" & r)
End With
For i = 3 To UBound(ar)
If Trim(ar(i, 2)) <> "" Then
d(Trim(ar(i, 2))) = ""
End If
Next i
For Each k In d.keys
n = 0
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 3 To UBound(ar)
If Trim(ar(i, 2)) = k Then
n = n + 1
br(n, 1) = n
For j = 2 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
End If
Next i
If dc.exists("部门" & k) Then
With Sheets("部门" & k)
rs = .Cells(Rows.Count, 6).End(xlUp).Row
If rs >= 14 Then .Range("e14:q" & rs) = Empty
.[e14].Resize(n, UBound(br, 2)) = br
End With
End If
Next k
Set d = Nothing
Set dc = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|