Merge all the remaining worksheets in the same workbook

Source: Internet
Author: User
Tags first row valid

The function of the following code is to merge all the remaining worksheets in the same workbook, appending the rest of the table's data to the first worksheet to form a complete unique table of data.

The code is as follows, and a code note will be attached later:

Dim Mycount as Integer

K = Worksheets (1). UsedRange.Rows.Count + 1

For MyTable = 2 to Worksheets.count

For i = 5 to Worksheets (MyTable). UsedRange.Rows.Count

For j = 1 to Worksheets (MyTable). UsedRange.Columns.Count

Worksheets (1). Cells (k, J). Value = Worksheets (MyTable). Cells (i, J). Value

Next J

K = k + 1

Next I

Next MyTable

Note that, as in the code above, only the fifth row of the other table's data to the last row of the data array added to the first table, the first row to the fourth row is the title, no append. For i = 5 represents the start of the array from line fifth.

Code explanation

K = Worksheets (1). UsedRange.Rows.Count + 1 Gets the line number of the last row of the first worksheet plus 1

For MyTable = 2 to Worksheets.count from the second worksheet to the last worksheet, so that you can append additional tables to the first table by looping

For i = 5 to Worksheets (MyTable). UsedRange.Rows.Count each worksheet, append to table one only from line fifth to the last row of valid data.

For j = 1 to Worksheets (MyTable). UsedRange.Columns.Count loops from the first column of each worksheet to the maximum column number of valid column data.

Worksheets (1). Cells (k, J). Value = Worksheets (MyTable). Cells (i, J). Value assigns the values of the cells of the valid data for other tables to the corresponding cells in the first worksheet.

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.