[英]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.