下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、把多个工作簿合并到一个工作簿作为新工作簿的一张表(宏代码)sub 合并当前目录下所有工作簿的全部工作表() dim mypath, myname, awbnamedim wb as workbook, wbn as string dim g as longdim num as long dim box as stringapplication.screenupdating = false mypath = activeworkbook.path myname = dir(mypath & & *.xls) awbname = activeworkbook.name num = 0do whil
2、e myname if myname awbname thenset wb = workbooks.open(mypath & & myname) num = num + 1with workbooks(1).activesheet.cells(.range(a65536).end(xlup).row + 2, 1) = left(myname, len(myname) - 4) for g = 1 to sheets.countwb.sheets(g).usedrange.copy .cells(.range(a65536).end(xlup).row + 1, 1) nextwbn = w
3、bn & chr(13) & wb.name wb.close falseend with end ifmyname = dir loop range(a1).selectapplication.screenupdating = truemsgbox 共合并了 & num & 个工作薄下的全部工作表。如下: & chr(13) & wbn, vbinformation, 提示end sub具体操作:在工作簿目录下新建一工作簿,工具-宏-编辑器-插入模块-粘贴代码=运行excel 如何将一个工作簿中的多个工作表合并到一张工作表上打开你的工作簿 新建一个工作表 在这个工作表的标签上右键 查看代码
4、你把下面的代码复制到里边去,然后 上面有个运行 运行子程序就可以了,代码如下,如果 出现问题你可以尝试工具 宏 宏安全性里把那个降低为中或者低再试试sub 合并当前工作簿下的所有工作表() application.screenupdating = falsefor j = 1 to sheets.countif sheets(j).name activesheet.name then x = range(a65536).end(xlup).row + 1 sheets(j).usedrange.copy cells(x, 1)end if nextrange(b1).select applic
5、ation.screenupdating = truemsgbox 当前工作簿下的全部工作表已经合并完毕!, vbinformation, 提示end sub把同一工作簿多张工作表合并到同一张工作表1新建一个工作表放在最左边,alt + f11 键打开代码框-插入-模块-复制以下代码alt + f8 键打开,运行该代码即可sub 合并()for i = 2 to sheets.count如果工作表的第一行都一样,就把下面 rows(1 &的 1 改成 2 就好了sheets(i).rows(1 & : & sheets(i).range(a60000).end(xlup).row). _ co
6、py range(a & range(a60000).end(xlup).row + 1)next end sub批量将多个 excel 中的多个工作簿合并到一个 excel 中将要合并的 excel 放到一个文件夹中,在这个目录中新建一个 excel,运行以下代码sub combinefiles()dim pathas stringdim filenameas stringdim lastcellas rangedim wkbas workbookdim wsas worksheetdim thiswbas stringdim mydir as stringmydir = thisworkb
7、ook.path & chdrive left(mydir, 1) find all the excel files chdir mydirmatch = dir$()thiswb = thisworkbook.name application.enableevents = false application.screenupdating = false path = mydirfilename = dir(path & *.xls, vbnormal) do until filename = if filename thiswb thenset wkb = workbooks.open(fi
8、lename:=path & & filename) for each ws in wkb.worksheetsset lastcell = ws.cells.specialcells(xlcelltypelastcell)if lastcell.value = and lastcell.address = range($a$1).address then elsews.copy after:=thisworkbook.sheets(thisworkbook.sheets.count) end ifnext ws wkb.close falseend iffilename = dir() lo
9、opapplication.enableevents = true application.screenupdating = trueset wkb = nothing set lastcell = nothingend sub“”“”at the end, xiao bian gives you a passage. minand once said, people who learn to learn are very happy people. in every wonderful life, learning is an eternal theme. as a professional
10、 clerical and teaching position, i understand the importance of continuous learning, life is diligent, nothing can be gained, only continuous learning can achieve better self. only by constantly learning and mastering the latest relevant knowledge, can employees from all walks of life keep up with the pace of enterprise development and innovate to meet the n
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年中职考试模拟题库带答案
- 2026年中级线路工题库(含答案)
- 2026年综合类常识知识考试题库及答案
- 2026年重庆市江津区双福双凤路幼儿园春季招聘备考题库及答案
- 2026年中级保管员题库及答案
- 2026年招护理!西宁市城北区朝阳社区卫生服务中心招聘考试备考题库(含答案)
- 国家开放大学一网一平台电大西方经济学经济学形考任务16题库及参考答案
- 2026年电子信息素养题库及参考答案
- 2026年有害生物初级题库带答案
- 2026年中专影像考试题库及答案
- 工会职工之家活动室建设方案
- 中级经济师知识产权专业知识与实务真题及解析(2026年)
- 老师家访培训课件
- 中建四局《高洁净芯片厂房项目技术要点交流汇报》(可编辑)
- 《JBT 6655-2013耐热圆柱螺旋压缩弹簧 技术条件》(2026年)实施指南
- 2025学年保定市十校高二语文上学期期中联考试卷附答案解析
- 2024-2025学年广东省广州市天河区八年级上学期期中数学试卷(含答案)
- 国家科技安全教学课件
- 小学保障学生每天综合体育活动时间不低于两小时实施方案(完整版)
- 汽车4S店售后服务流程说明书
- 低血糖临床表现及处理措施
评论
0/150
提交评论