|
代码如下。。。。
Sub test()
Application.ScreenUpdating = False
Dim wb As Workbook, sht As Worksheet, sh As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("提取条件")
Set sh = wb.Sheets("提取结果示例")
p = wb.Path & "\源文件\"
arr = sht.[a1].CurrentRegion
' ReDim ar(1 To 1)
ReDim br(1 To 1)
n = 0
For i = 2 To UBound(arr, 2)
n = n + 1
If arr(2, i) <> Empty Then x = arr(2, i)
If arr(3, i) <> Empty Then ReDim Preserve br(1 To n): br(n) = arr(3, i)
Next
n = 0
f = Dir(p & "*.xls*")
ReDim brr(1 To 10000, 1 To UBound(br) + 1)
Do While f <> ""
With Workbooks.Open(p & f, 0)
For i = 1 To x
With .Sheets(x)
n = n + 1
brr(n, 1) = n
For j = 1 To UBound(br)
brr(n, j + 1) = .Range(br(j))
Next
End With
Next
.Close 0
End With
f = Dir
Loop
With sh
.[j1].CurrentRegion.Clear
.[j1].Resize(, UBound(brr, 2)) = [{"序号","名称","箱 种","箱子型号","数 量","参考重量","产品单重"}]
.[j2].Resize(6, UBound(brr, 2)) = brr
.[j1].CurrentRegion.HorizontalAlignment = xlCenter
.[j1].CurrentRegion.Borders.LineStyle = 1
.[j1].CurrentRegion.Columns.AutoFit
End With
Beep
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|