|
本帖最后由 李波001 于 2024-11-12 14:36 编辑
Sub TQsj()
Application.ScreenUpdating = False: Application.DisplayAlerts = False
Dim ws As Worksheet, wb As Workbook, sh As Worksheet, p As String, f As String, arr() As Variant, brr() As Variant, r As Long, C As Long
Set ws = ThisWorkbook.Sheets(1)
p = ThisWorkbook.Path & "\aa\" '设置路径
f = Dir(p)
arr = ws.[a1].CurrentRegion.Value ' 初始化数组
ReDim brr(1 To 999, 1 To 10)
r = 1
Do While f <> ""
Set wb = Workbooks.Open(p & f)
Set sh = wb.Sheets(1)
brr(r, 1) = f
brr(r, 2) = sh.Name
brr(r, 3) = Right(sh.Cells(3, "A").Value, Len(sh.Cells(3, "A").Value) - InStr(sh.Cells(3, "A").Value, "地区3:") - 3)
brr(r, 4) = sh.Cells.Find("户主").Offset(0, -2).Value
brr(r, 5) = Application.WorksheetFunction.CountA(sh.Range("B9:B17"))
brr(r, 10) = Right(sh.Cells(44, "A").Value, Len(sh.Cells(44, "A").Value) - InStr(sh.Cells(44, "A").Value, ":"))
For C = 6 To 9
If arr(8, C) <> "" Then brr(r, C) = sh.Range(arr(8, C)).Value
Next C
r = r + 1
wb.Close SaveChanges:=False
f = Dir
Loop
' 将结果写入工作表
ws.[a10].Resize(UBound(brr, 1), UBound(brr, 2)) = brr
Application.ScreenUpdating = True: Application.DisplayAlerts = True
End Sub
|
|