Merging multiple Excel file contents

Source: Internet
Author: User

Place the Excel document you want to merge in the same folder, and then create a new Excel file in the folder to open Excel, press ALT+F11, or
Click Tools, Macro, VB Editor, pop-up editor, click Insert Module, enter the following code in the new blank window:
Sub Merge all worksheets for all workbooks in the current directory () Dim MyPath, MyName, awbname Dim Wb As Workbook, wbn as String Dim G As Long Dim N Um as Long Dim BOX as String flag=0application.screenupdating=False MyPath=Activeworkbook.path MyName= Dir (MyPath &"\ "&"*.xls")Awbname =activeworkbook.name Num=0Do While MyName<>""If MyName<>Awbname then Set Wb= Workbooks.Open (MyPath &"\ "& MyName)num = num +1With Workbooks (1). ActiveSheet for G=1To sheets.count If flag=0then//Here I have to make a judgment, if it is the first document to take the head title also, not just copy the content wb.sheets (G). Usedrange.copy. Cells (. Range ("A65536"). End (Xlup). Row,1) Flag=1Else wb.sheets (G). Range ("A2", Wb.sheets (G). Cells.specialcells (xlCellTypeLastCell)). Copy. Cells (. Range ("A65536"). End (Xlup). Row +1,1) End If Next wbn= WBN & Chr ( -) &wb.name wb.close False End with end If MyName=Dir Loop Range ("A1"). Select application.screenupdating=True MsgBox"merged together."& Num &"Worksheets under a workbook. as follows:"& Chr ( -) & Wbn, vbinformation,"Tips"End Sub
Save---Point to perform key OK!!!

Merging multiple Excel file contents

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.