|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub TEST()
Dim ar, br$(), cr, i&, j&, r&, dic As Object, vKey, t#, wks As Worksheet
DoApp False
Set dic = CreateObject("Scripting.Dictionary")
t = Timer
ar = [A1].CurrentRegion
For i = 2 To UBound(ar): dic(ar(i, 9)) = dic(ar(i, 9)) & "," & i: Next
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For j = 1 To UBound(ar, 2): br(1, j) = ar(1, j): Next
With Workbooks.Add
For Each vKey In dic.keys
.Worksheets.Add after:=.Worksheets(.Worksheets.Count)
r = 1
With .ActiveSheet
.Name = vKey
cr = Split(dic(vKey), ",")
For i = 1 To UBound(cr)
r = r + 1
For j = 1 To UBound(ar, 2)
br(r, j) = ar(cr(i), j)
Next j
Next i
With .[A1].Resize(r, UBound(br, 2))
.Value = br
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
.Font.Size = 10
.Rows(1).Font.Bold = True
.EntireColumn.AutoFit
.EntireRow.AutoFit
End With
End With
Next
For Each wks In .Sheets
If wks.Name Like "*Sheet*" Then wks.Delete
Next
End With
Set dic = Nothing
DoApp
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.00") & " 秒", 64
End Sub
Function DoApp(Optional b As Boolean = True)
With Application
.ScreenUpdating = b
.DisplayAlerts = b
.Calculation = -b * 30 - 4135
End With
End Function
|
评分
-
2
查看全部评分
-
|