下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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届4月初三教学质量测评化学试题含解析
- 2026年防走失定位产品技术对比与选择
- 2026年“2 10 N”服务体系:数据交易所与生态伙伴协同模式设计
- 2026年智能网联汽车自动驾驶数据记录存储规范
- 2026年矿区源网荷储一体化:分布式光伏 储能 采矿负荷
- 2026年教师从知识传授者向学习引导者能力激发者转型路径
- 2025年临床执业《儿科学》专项练习
- 房地产行业项目负责人面试全攻略
- 酒店旅游行业投资计划与实施策略
- 2024-2025年上海中考英语真题及答案解析
- 第6课第1课时呵护花季激扬青春【中职专用】《心理健康与职业生涯》(高教版2023基础模块)
- 道路绿化养护投标方案(技术方案)
- 品牌策划与推广(第3版 数字教材版) 课件全套 人大 第1-9章 品牌的本质及其定位决策-营销活动策划与管理
- 爆破作业人员教育培训制度
- 辊道窑作业标准指导书
- GB/T 24421.1-2023服务业组织标准化工作指南第1部分:总则
- 井巷用全自动全液压凿岩台车设计书
- 蚕桑产业建设汇报材料(四)
- 借调人员协议-三方协议
- 2022版化学检验工高级工考核题库(全真题库)
评论
0/150
提交评论