|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
neke520 发表于 2014-5-11 21:49
赵版主,附件只改了你在6楼测试附件的第一个工作薄里的子表名称,就统计不出结果 - Sub Macro1()
- Dim MyPath$, MyName$, sh As Worksheet, arr$(), i&, r&, wb As Workbook
- Application.ScreenUpdating = False
- ReDim arr(2 To Worksheets.Count)
- For i = 2 To Worksheets.Count
- With Worksheets(i)
- .UsedRange.Offset(3).Clear
- arr(i) = .Name
- End With
- Next
- Set wb = ThisWorkbook
- r = Rows.Count
- MyPath = ThisWorkbook.Path & ""
- MyName = Dir(MyPath & "*.xlsx")
- Do While MyName <> ""
- With GetObject(MyPath & MyName)
- For Each sh In .Sheets
- For i = 2 To UBound(arr)
- If InStr(sh.Name, arr(i)) Then
- sh.UsedRange.Offset(3).Copy wb.Worksheets(arr(i)).Cells(r, 1).End(xlUp).Offset(1)
- Exit For
- End If
- Next
- Next
- .Close False
- End With
- MyName = Dir
- Loop
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|