简体   繁体   English

如何将一个文件夹中多个 excel 工作簿中除工作表 1 和 2 之外的所有工作表复制到另一个工作簿中

[英]How to Copy every sheet except sheet 1 and 2 on multiple excel workbook in one folder into another workbook

I really appreciate if someone here would help me crack this problem which i cant find the solution (and sorry for my bad english).如果这里有人能帮助我解决这个我找不到解决方案的问题,我真的很感激(抱歉我的英语不好)。

So i have multiple excels in one folder.所以我在一个文件夹中有多个 excel。 every excel in it have same format 1st sheet for reference of every sheet, 2nd sheet for consolidation data, and 3rd sheet and the rest for the data to be consolidated.其中每excel都有相同格式的第1张表供每张表参考,第2张表用于合并数据,第3张表和rest用于要合并的数据。 Every excel in the folder have various amount of sheet.文件夹中的每个 excel 都有不同数量的工作表。

What i want to do is i want to copy data from range A27:AJ500 that begin from 3rd sheet to every sheet after, into another new workbook in sheet1 and paste it begin from cell A27 over and over into the bottom and looping for every excel in folder.我想做的是我想将范围 A27:AJ500 中的数据从第 3 张开始复制到之后的每张工作表中,复制到工作表 1 中的另一个新工作簿中,并将它从单元格 A27 开始一遍又一遍地粘贴到底部并循环每个 excel在文件夹中。

i dont have enough ability yet to write my own script but i managed to understand some and combine it into this script.我还没有足够的能力编写自己的脚本,但我设法理解了一些并将其组合到这个脚本中。

Sub Download_Data()

Path = "C:\Users\ASUS\Desktop\Done\"
Filename = Dir(Path & "*.xlsm")

'to open every excel in my folder
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True '--> i only managed to do it right till here

'supposed to copy range in every sheet of excel in my folder into different workbook
For Each ws In thiswoorkbook.Worksheets '--> i try write this code but i am confused to do what i want from here and i know this code is nowhere near true
    With ws
        If .Name <> "GABUNGAN" Then
        range("A27:AJ500").Select
        Selection.copy
        Workbooks("Tes.xlsm").range("A27").PasteSpecial Paste:=xlPasteValues
        End If
    End With
Next ws

Workbooks(Filename).Close
Filename = Dir()
Loop

Application.Goto ActiveWorkbook.Sheets("sheet1").range("A1")

End Sub

I've been searching for the code not only i cant customize it to this code but also i cant understand what is wrong in the code therefore i write this question.我一直在寻找代码,不仅我无法将其自定义为这段代码,而且我也无法理解代码中的错误,因此我写了这个问题。 Any help will be appreciated, thanks in advance for your attention wish you safe and sound.任何帮助将不胜感激,在此先感谢您的关注,祝您平安无事。

Try this: (tested)试试这个:(已测试)

Dim sourcewb As Workbook
Dim destwb As Workbook
Dim y As Long
Dim ws As Worksheet
Dim strPath As String, strFilename As String

strPath = "C:\Users\ASUS\Desktop\Done\"
strFilename = Dir(strPath & "*.xlsm")

y = 27
Set destwb = ThisWorkbook
Do While strFilename <> ""
    Set sourcewb = Workbooks.Open(Filename:=strPath & strFilename, ReadOnly:=True)
    For Each ws In sourcewb.Worksheets
        With ws
            If .Name <> "name of reference sheet" And .Name <> "name of consolidation sheet" Then
                .Range("A27:AJ500").Copy
                destwb.Worksheets("sheet1").Range("A" & y).PasteSpecial Paste:=xlPasteValues
                y = y + (500 - 27) + 1
            End If
        End With
    Next ws
    sourcewb.Close False
    strFilename = Dir()
Loop

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel工作表:将数据从一个工作簿复制到另一个工作簿 - Excel sheet: Copy data from one workbook to another workbook 将工作表从excel工作簿复制到另一个工作簿 - Copy sheet from excel workbook to another workbook 将Excel工作表复制到另一个工作簿中的另一个工作表 - Copy Excel Sheet into another Sheet in another Workbook 使用Python(和DataNitro)将单元格从一个Excel工作簿中的特定工作表复制到另一个Excel工作簿中的特定工作表 - Using Python (and DataNitro) to copy cells from a particular sheet in one Excel workbook, to a particular sheet in another Excel workbook VBA将数据从一个工作簿表复制到另一工作簿表 - VBA copy data from one workbook sheet to another workbook sheet 如何使用 Python 将数据从一个 Excel 工作表复制到同一工作簿的另一工作表? - How to copy data from One Excel sheet to another sheet for same Workbook Using Python? 将工作表复制到另一个工作簿 - Copy sheet to another workbook Excel VBA-如何使用不同的子例程将行从工作簿的行复制到另一个工作簿的工作表 - Excel VBA - How to copy row by row from a sheet of workbook to another Workbook's sheet using different subroutine 将Excel 2010工作表复制到另一个工作簿 - Copy excel 2010 sheet to another workbook 如何复制工作簿中一个工作表/选项卡中使用的代码以在同一工作簿中的另一个工作表/选项卡中创建报告 - How to copy the code used in one sheet/tab in a workbook to create a report in another sheet/tab within the same workbook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM