|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub chaifen()
Set d = CreateObject("scripting.dictionary")
For Each sh In Sheets
r = sh.Rows(1).Find("id", , , 1).Column
ar = sh.[a1].CurrentRegion
For i = 2 To UBound(ar)
If Trim(ar(i, r)) <> "" Then
d(Trim(ar(i, r))) = ""
End If
Next i
Next sh
Application.SheetsInNewWorkbook = ThisWorkbook.Worksheets.Count
For Each k In d.keys
m = 0
Set wb = Workbooks.Add
For Each sh In ThisWorkbook.Worksheets
n = 0
m = m + 1
r = sh.Rows(1).Find("id", , , 1).Column
Set rn = sh.Rows(1)
ar = sh.[a1].CurrentRegion
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If Trim(ar(i, r)) = k Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
End If
Next i
sh.UsedRange.Copy wb.Worksheets(m).[a1]
wb.Worksheets(m).UsedRange.Offset(1).ClearContents
wb.Worksheets(m).[a2].Resize(n, UBound(br, 2)) = br
wb.Worksheets(m).Name = sh.Name
Next sh
wb.SaveAs Filename:=ThisWorkbook.Path & "\" & k
wb.Close
Next k
MsgBox "ok!"
End Sub
|
|