Using VBA to merge multiple tables in Excel

Source: Internet
Author: User

Integration of multiple tables in Excel using VBA

Requirement

Keep the column name, copy the data in each excel file, and merge it to an Excel file.

Procedure

  1. Put the files to be merged in the same folder and copy them. (PS: it is best not to directly operate the original data file to avoid operation failures and data loss)
  2. Create a merge. XLSX under this directory"
  3. Double-hitting merge. XLSX"
  4. At the same time, press Alt + F11
  5. Appears. merge can be completed by text operations in the figure.

 

  1. Complete

 

 

 

 

Appendix code
Sub combines all worksheets in all workbooks in the current directory () dim mypath, myname, awbname dim WB as workbook, WBN as string dim G as long dim num as long dim box as string flag = 0 application. screenupdating = false mypath = activeworkbook. path myname = Dir (mypath &"\"&"*. xls ") awbname = activeworkbook. name num = 0 do while myname <> "" If myname <> awbname then set WB = workbooks. open (mypath & "\" & myname) num = num + 1 with work Books (1 ). activesheet for G = 1 to sheets. count if flag = 0 then WB. sheets (g ). usedrange. copy. cells (. range ("a65536 "). end (xlup ). row, 1) Flag = 1 else 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 (13) & WB. name WB. close false end with end if myname = dir loop range ("A1 "). select application. Screenupdating = true msgbox "combines all worksheets in the" & num & "workbook. As follows: "& CHR (13) & wBN, vbinformation," prompt "End sub

 

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.