|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub test()
Dim ar, i&, dic As Object, vKey, rngData As Range, wks As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
With Worksheets("原始数据")
With .[A1].CurrentRegion
ar = .Value
Set rngData = .Rows("1:2")
For i = 3 To UBound(ar)
vKey = Mid(ar(i, 1), 1, 1) & "年级" & Val(Mid(ar(i, 1), 2, 2)) & "班 "
If Not dic.exists(vKey) Then
Set dic(vKey) = rngData
End If
Set dic(vKey) = Union(dic(vKey), .Rows(i))
Next
End With
For Each wks In Worksheets
If wks.Name <> .Name Then wks.Delete
Next
End With
For Each vKey In dic.keys
With Worksheets.Add(after:=Worksheets(Worksheets.Count))
.Name = vKey
dic(vKey).Copy
.[A1].PasteSpecial xlPasteColumnWidths
dic(vKey).Copy .[A1]
End With
Next
Set dic = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|