|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub TEST7()
Dim ar, br, i&, j&, r&, dic As Object, t#
Dim strPath$, strFileName$, iPosCol&
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
t = Timer
ar = [A1].CurrentRegion.Value
ReDim br(1 To 10 ^ 4, 1 To UBound(ar, 2)) As String
For j = 1 To UBound(br, 2)
br(1, j) = ar(1, j)
If j > 3 Then dic(br(1, j)) = j
Next j
r = 1
strPath = ThisWorkbook.Path & "\"
strFileName = Dir(strPath & "*.xls")
Do Until strFileName = ""
If strFileName <> ThisWorkbook.Name Then
With Workbooks.Open(strPath & strFileName)
ar = Worksheets(1).[A22].CurrentRegion.Value
For i = 2 To UBound(ar)
r = r + 1
For j = 1 To UBound(ar)
If dic(ar(1, j)) Then
iPosCol = dic(ar(1, j))
br(r, iPosCol) = ar(i, j)
End If
Next j
br(r, 1) = r - 1
br(r, 2) = Worksheets(1).Range("H6").Value
br(r, 3) = Worksheets(1).Range("D20").Value
Next i
.Close False
End With
End If
strFileName = Dir
Loop
Cells.Clear
[A1].Resize(r, UBound(br, 2)) = br
Set dic = Nothing
Application.ScreenUpdating = True
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.00") & " 秒", 64
End Sub
|
评分
-
1
查看全部评分
-
|