|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 提取数据()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim i As Long, r As Long, rs As Long
Dim d As Object
Set d = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\"
With Sheets("数据提取")
y = .Cells(1, Columns.Count).End(xlToLeft).Column
.[a1].CurrentRegion.Offset(1).Borders.LineStyle = 0
.[a1].CurrentRegion.Offset(1) = Empty
ar = .Range(.Cells(1, 1), .Cells(5000, y))
For j = 2 To y
d(ar(1, j)) = j
Next j
f = Dir(lj & "*.xls*")
n = 1
Do While f <> ""
If f <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
rs = .Cells(Rows.Count, 2).End(xlUp).Row
ys = .Cells(2, Columns.Count).End(xlToLeft).Column
br = .Range(.Cells(1, 1), .Cells(rs, ys))
End With
For i = 3 To UBound(br)
If Trim(br(i, 2)) <> "" Then
n = n + 1
ar(n, 1) = n - 1
For j = 2 To UBound(br, 2)
lh = d(br(2, j))
If lh <> "" Then
ar(n, lh) = br(i, j)
End If
Next j
End If
Next i
wb.Close False
End If
f = Dir
Loop
.[a1].Resize(n, y) = ar
.[a1].Resize(n, y).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|