|
你试试
Sub 全部合并()
Dim wk As Workbook, brr(1 To 10000, 1 To 100)
Set d = CreateObject("scripting.dictionary")
p = ThisWorkbook.Path & "\"
sh = Dir(p & "*.xlsx")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Do While sh <> ""
If sh <> ThisWorkbook.Name Then
Set wk = Workbooks.Open(p & sh)
arr = wk.Sheets(1).UsedRange
For I = 1 To UBound(arr)
For j = 1 To UBound(arr, 2)
If IsError(arr(I, j)) Then arr(I, j) = ""
If InStr(arr(I, j), "年度") Then
r = I + 1
For jj = 1 To UBound(arr, 2)
If arr(r, jj) = "" Then Exit For
If Not d.exists((arr(r, jj))) Then
d(arr(r, jj)) = d.Count + 1
End If
Next jj
ElseIf InStr(arr(I, j), "合计") Then
s = I - 1
Exit For
End If
Next j
Next I
For I = r + 1 To s
k = k + 1
If arr(I, d("姓名")) = "" Then Exit For
For j = 1 To UBound(arr, 2)
If arr(r, j) = "" Then Exit For
brr(k, 1) = wk.Name
brr(k, 2) = wk.Sheets(1).Name
brr(k, d(arr(r, j)) + 2) = arr(I, j)
Next j
Next I
wk.Close
End If
sh = Dir
Loop
With Sheets("1-1全部列字段合并")
.UsedRange.Offset(0, 0) = ""
.Range("a1") = "工作簿"
.Range("b1") = "工作表"
.Range("c1").Resize(1, d.Count) = d.keys
.Range("a2").Resize(k, d.Count) = brr
.Cells.Columns.AutoFit
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
|
评分
-
1
查看全部评分
-
|