|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
kszcs 发表于 2013-9-17 22:32
zhaogang1960 老师:
能在汇总表的前面自动加入簿名和表名的两列吗?
如果各表的数据起始行变化,修改哪 ... - Sub Macro1()
- Dim MyPath$, MyName$, sh As Worksheet, sht As Worksheet
- Application.ScreenUpdating = False
- Set sh = ActiveSheet
- MyPath = ThisWorkbook.Path & ""
- MyName = Dir(MyPath & "*.xls")
- [a1].CurrentRegion.Offset(2).Clear
- Do While MyName <> ""
- If MyName <> ThisWorkbook.Name Then
- With GetObject(MyPath & MyName)
- For Each sht In .Sheets
- If sht.[a1].CurrentRegion.Rows.Count > 2 Then
- lr = sh.[a1].CurrentRegion.Rows.Count + 1
- r = sht.[a1].CurrentRegion.Rows.Count - 2
- sh.Cells(lr, 1).Resize(r) = MyName
- sh.Cells(lr, 2).Resize(r) = sht.Name
- sht.[a1].CurrentRegion.Offset(2).Copy sh.Cells(lr, 3)
- End If
- Next
- .Close False
- End With
- End If
- MyName = Dir
- Loop
- Application.ScreenUpdating = True
- MsgBox "ok"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|