|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub test()
Dim ar, i&, f, strFileName$, p$, vKey, strFolder$, dic As Object, Rng As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set dic = CreateObject("Scripting.Dictionary")
p = ThisWorkbook.Path & "\"
For Each f In CreateObject("Scripting.FileSystemObject").GetFolder(p & "数据\").Files
If f.Name Like "*.xlsx" Then
With GetObject(f)
dic.RemoveAll
With .Sheets(1).[A1].CurrentRegion
ar = .Value
Set Rng = .Range("A1:A2").Resize(, UBound(ar, 2))
For i = 3 To UBound(ar)
vKey = ar(i, 8) & "数据"
If Not dic.exists(vKey) Then
Set dic(vKey) = Rng
End If
Set dic(vKey) = Union(dic(vKey), .Cells(i, 1).Resize(, UBound(ar, 2)))
Next
End With
For Each vKey In dic.keys
strFolder = p & vKey & "\"
If Dir(strFolder, vbDirectory) = "" Then MkDir strFolder
strFileName = strFolder & vKey & "-" & f.Name
With Workbooks.Add
With .Sheets(1)
dic(vKey).Copy
.Cells(1, 1).PasteSpecial xlPasteColumnWidths
dic(vKey).Copy .Cells(1, 1)
End With
.SaveAs strFileName
.Close
End With
Next
.Close False
End With
End If
Next
Set Rng = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|