excel如何合并同类型工作表
时间:2022-09-08 10:55:36
一个文件夹下面有多个excel工作薄,每个工作薄文件下面有不固定张数的同类型关键标题的工作表。
现在的问题,如何将这些多个文件实现合并到一张工作表。
一般的做法,通过复制粘贴,实现合并工作表。要高效,可以使用VBA代码来实现合并工作表。
合并工作表操作步骤:
新建一个excel文件,按ALT+F11,打开VBE编辑器,复制下面的代码,然后运行,选择文件夹下面的所有excel文件,执行合并工作表。
SubUnionWorksheets()
Application.ScreenUpdating=False
DimljAsString
DimdirnameAsString
DimnmAsString
lj=ActiveWorkbook.Path
nm=ActiveWorkbook.Name
dirname=Dir(lj&"\*.xls*")
Cells.Clear
DoWhiledirname<>""
Ifdirname<>nmThen
Workbooks.OpenFilename:=lj&"\"&dirname
Workbooks(nm).Activate’复制新打开工作簿的第一个工作表的已用区域到当前工作表
Workbooks(dirname).Sheets(1).UsedRange.Copy_
Range("A65536").End(xlUp).Offset(1,0)
Workbooks(dirname).CloseFalse
EndIf
dirname=Dir
Loop
EndSub
说明:上面代码是合并xlsx文件,如果是合并excel2007的文件,需要将:dirname=Dir(lj&"\*.xls*"),xls改为.xlsx。
标签:合并,多个,工作,文件,Excel函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Word文档中汉字怎么添加拼音标注
2023-11-19 12:37:26
![](https://img.aspxhome.com/file/2023/0/18010_0s.jpg)
Word2016文字的边框怎么设置 Word2016文字设置框框教程
2022-07-13 06:44:52
![](https://img.aspxhome.com/file/2023/6/24676_0s.jpg)
Word怎么转换成PPT
2022-01-29 19:15:19
EXCEL中在单元格公式编辑中的大括号{}是什么意思
2023-04-05 03:47:47
Excel内部函数之五:逻辑函数使用详解
2022-08-11 19:16:20
安装win10系统用uefi还是legacy?UEFI和Legacy有什么区别
2023-08-02 21:59:59
![](https://img.aspxhome.com/file/2023/1/46611_0s.jpg)
Apple Music 新增新年歌单,快来分享给好友
2023-10-05 13:36:06
![](https://img.aspxhome.com/file/2023/2/46202_0s.jpg)
Excel表格中利用公式划分成绩等级的操作方法
2022-02-23 02:24:55
word操作的撤销和恢复 基础教程
2022-05-05 00:08:19
![](https://img.aspxhome.com/file/2023/4/32394_0s.jpg)
excel2003插入日历控件的教程
2022-01-25 06:47:24
设置word背景图片的两种方法
2023-10-03 20:04:54
如何免费获取office2007的序列号
2023-08-07 09:17:08
![](https://img.aspxhome.com/file/2023/6/15436_0s.png)
FREQUENCY函数分段计数
2023-06-04 00:15:20
![](https://img.aspxhome.com/file/2023/5/a142265_0s.png)
word 字符间距变大了,有哪些原因?
2023-05-03 09:41:13
![](https://img.aspxhome.com/file/2023/7/34137_0s.png)
excel怎么把计算结果显示的其他单元格
2022-12-27 00:43:54
WPS Excel设置表格只能填写不能修改方法!
2022-02-19 08:26:33
![](https://img.aspxhome.com/file/2023/7/a153467_0s.png)
Word2016怎么将文字批量替换成图片?
2022-09-20 17:18:36
![](https://img.aspxhome.com/file/2023/1/22781_0s.png)
四个office办公软件,你如何选择?
2023-11-09 19:29:21
![](https://img.aspxhome.com/file/2023/2/16772_0s.jpg)
word Tab键的 7 种高效用法
2023-01-31 14:37:38
Word中自动更正功能的实用教程
2023-12-08 10:49:54