|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
参与一下。。。
- Sub ykcbf() '//2024.8.7
- Set fso = CreateObject("scripting.filesystemobject")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set sh = ThisWorkbook.Sheets("Sheet1")
- With sh
- .[c2:f10000].ClearContents
- r1 = sh.[a1].Value
- st = sh.[a2].Value
- zrr = .[c1:e1]
- End With
- p = ThisWorkbook.Path & ""
- ReDim brr(1 To 10000, 1 To 4)
- For Each f In fso.GetFolder(p).Files
- If LCase$(f.Name) Like "*.xlsb" Then
- fn = fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .Cells(1, "XFD").End(1).Column
- arr = .[a1].Resize(r, c)
- End With
- wb.Close False
- For j = 1 To UBound(arr, 2)
- If arr(r1, j) = st Then
- m = m + 1
- jj = j
- For x = 1 To UBound(zrr, 2)
- brr(m, x) = arr(zrr(1, x), jj)
- Next
- brr(m, 4) = fn & 列号转列符(jj)
- End If
- Next
- End If
- Next f
- With sh
- If m > 0 Then
- .[c2].Resize(m, 4) = brr
- Else
- MsgBox "没查到对应数据!请重新输入数据查询!"
- Exit Sub
- End If
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|