Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 8102|回复: 7

[已解决]怎么用宏实现多表合并

[复制链接]
发表于 2013-7-6 20:44 | 显示全部楼层 |阅读模式
怎么用宏实现多表和并。附件里的表1/表2/表3/表4/自动合并成生产报表。如果下次有表5/表6/表7。。。。一直表100的放在一起。自动合并成生产报表的模式。在线等待。谢谢各位大虾!
最佳答案
2013-7-6 21:02
其实数字偏长的你在前面加个单引号问题就解决了,昨天合并后我就看到了。

新建文件夹1 (3).rar

29.85 KB, 下载次数: 120

发表于 2013-7-6 21:01 | 显示全部楼层
昨天不是帮你写过一个么,今天要求变了?
回复

使用道具 举报

发表于 2013-7-6 21:02 | 显示全部楼层    本楼为最佳答案   
其实数字偏长的你在前面加个单引号问题就解决了,昨天合并后我就看到了。
回复

使用道具 举报

 楼主| 发表于 2013-7-6 21:31 | 显示全部楼层
hwc2ycy 发表于 2013-7-6 21:02
其实数字偏长的你在前面加个单引号问题就解决了,昨天合并后我就看到了。

你好:因为我是新手。。所以朋友的教我不懂呐。需要朋友整个编码呢{:041:}
回复

使用道具 举报

发表于 2013-7-6 21:34 | 显示全部楼层
我也想学学
回复

使用道具 举报

 楼主| 发表于 2013-7-6 21:37 | 显示全部楼层
hwc2ycy 发表于 2013-7-6 21:02
其实数字偏长的你在前面加个单引号问题就解决了,昨天合并后我就看到了。

  • Sub 合并工作表()
  •     Dim strPath As String, strFile As String
  •     Dim objwb As Workbook, rg As Range
  •     Dim arr, strMsg As String
  •     On Error GoTo ErrorHandler
  •     With Application
  •         .ScreenUpdating = False
  •         .DisplayAlerts = False
  •         .EnableEvents = False
  •         .Calculation = xlCalculationManual
  •     End With
  •     strPath = ThisWorkbook.Path & Application.PathSeparator
  •     strFile = Dir(strPath & "*.xls")
  •     Do While Len(strFile)
  •         Set rg = Sheet1.Cells(Rows.Count, 1).End(xlUp)
  •         If strFile <> ThisWorkbook.Name Then
  •             strMsg = strMsg & strFile & vbCr
  •             With GetObject(strPath & strFile)
  •                 If rg.Row <> 1 Then
  •                     arr = .Worksheets("sheet1").UsedRange.Offset(1).Value
  •                 Else
  •                     arr = .Worksheets("sheet1").UsedRange.Value
  •                 End If
  •                 Windows(.Name).Visible = True
  •                 .Close False
  •             End With
  •             If rg.Row = 1 Then
  •                 rg.Resize(UBound(arr), UBound(arr, 2)).Value = arr
  •             Else
  •                 rg.Offset(1).Resize(UBound(arr), UBound(arr, 2)).Value = arr
  •             End If
  •         End If
  •         strFile = Dir
  •     Loop
  •     With rg.CurrentRegion.Borders
  •         .LineStyle = 1
  •         .ColorIndex = 16
  •     End With
  •     With Application
  •         .ScreenUpdating = True
  •         .DisplayAlerts = True
  •         .EnableEvents = True
  •         .Calculation = xlCalculationAutomatic
  •     End With
  •     If Len(strMsg) Then
  •         MsgBox "合并完成" & vbCrLf & "导入的文件如下:" & vbCrLf & strMsg
  •     End If
  •     Exit Sub
  • ErrorHandler:
  •     MsgBox Err.Number & vbCrLf & Err.Description
  •     Err.Clear
  •     If ActiveWorkbook.Name <> ThisWorkbook.Name Then
  •         ActiveWorkbook.Close False
  •     End If
  • End Sub
回复

使用道具 举报

发表于 2013-7-6 21:43 | 显示全部楼层
本帖最后由 ligh1298 于 2013-7-6 21:47 编辑

楼主:是不是想要这样的?见附件!

多工作表合并.rar

48.7 KB, 下载次数: 276

回复

使用道具 举报

 楼主| 发表于 2013-7-6 21:47 | 显示全部楼层
ligh1298 发表于 2013-7-6 21:43
楼主:是不是想要这样的?见附件!

亲你那只有表格文本格式呐。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-24 20:05 , Processed in 0.313273 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表