|
改了一下,按照黄色单元格提取的
Sub 指定合并()
Dim wk As Workbook
Set d = CreateObject("scripting.dictionary")
p = ThisWorkbook.Path & "\"
sh = Dir(p & "*.xlsx")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Sheets("1-2指定列字段合并")
For j = 3 To 100
If .Cells(3, j) = "" Then Exit For
n = n + 1
d(.Cells(3, j).Value) = n
Next j
End With
ReDim brr(1 To 10000, 1 To d.Count + 2)
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
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
If d.exists(arr(r, j)) Then
brr(k, 1) = wk.Name
brr(k, 2) = wk.Sheets(1).Name
brr(k, d(arr(r, j)) + 2) = arr(I, j)
End If
Next j
Next I
wk.Close
End If
sh = Dir
Loop
With Sheets("1-2指定列字段合并")
.UsedRange.Offset(3, 0) = ""
.Range("a3") = "工作簿"
.Range("b3") = "工作表"
.Range("a4").Resize(k, d.Count + 2) = brr
.Cells.Columns.AutoFit
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
|
评分
-
1
查看全部评分
-
|