|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub chaxun()
Application.ScreenUpdating = False
Set d = CreateObject("scripting.dictionary")
With Sheets("sheet1")
xh = .[b2]
xm = .[b3]
If xh = "" Then MsgBox "请输入姓名所在列的列号": Exit Sub
If xm = "" Then MsgBox "请输入姓名": Exit Sub
y = .Cells(7, Columns.Count).End(xlToLeft).Column
If y < 4 Then MsgBox "请输入科目名称!": Exit Sub
.UsedRange.Offset(7) = Empty
ar = .Range(.Cells(7, 1), .Cells(100, y))
For j = 4 To UBound(ar, 2)
If Trim(ar(1, j)) <> "" Then
d(Trim(ar(1, j))) = j
End If
Next j
f = Dir(ThisWorkbook.Path & "\*.xls*")
n = 1
Do While f <> ""
If f <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & f, 0)
For Each sh In wb.Worksheets
br = sh.UsedRange
For i = 9 To UBound(br)
If Trim(br(i, xh)) = Trim(xm) Then
n = n + 1
ar(n, 1) = sh.Name
ar(n, 2) = br(2, 1)
ar(n, 3) = xm
For j = 2 To UBound(br, 2)
m = d(Trim(br(8, j)))
If m <> "" Then
ar(n, m) = br(i, j)
End If
Next j
End If
Next i
Next sh
wb.Close False
End If
f = Dir
Loop
.[a7].Resize(n, UBound(ar, 2)) = ar
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|