[算表] 多個檔案、特定分頁 合併至一個 (VBA)
軟體: EXCEL
版本:2007
想要將一個資料夾下的所有檔案(皆有相同的Sheet)
和在一個檔案的Sheet裡
Ex. RawData 資料夾下 有A B C...很多個檔,每個都有很多個Sheet
要將每個檔的 "RSO review" 這個sheet 匯總至 Data Pooling這個檔
之前爬文(文章代碼: #1A4E0mzs),修改了別人的VBA如下
Option Explicit
Sub A()
Dim path As String
Dim obApp As New Excel.Application
Dim myFso: Set myFso = CreateObject("Scripting.FileSystemObject")
Dim wbnew, myfile
Dim Start As Integer, rCount As Integer
'要處理的目錄
path = "C:\Documents and Settings\asus\My Documents\VBA\RawData\"
Dim wb: Set wb = ThisWorkbook
obApp.DisplayAlerts = False
obApp.ScreenUpdating = False
obApp.EnableEvents = False
Dim myfiles: Set myfiles = myFso.GetFolder(path).Files
For Each myfile In myfiles
If myfile.Name Like "*.xlsx" Then
Set wbnew = obApp.Workbooks.Open(path & myfile.Name)
With wbnew.Worksheets("RSO review")
Start = wb.Sheets(1).Range("A1").CurrentRegion.Rows.Count + 2
rCount = .Cells.SpecialCells(xlCellTypeLastCell).Row
.Range(.Cells(3, 1), .Cells(rCount, .Columns.Count)).EntireRow.Copy
wb.Sheets(1).Paste Destination:=ActiveWorkbook.Sheets(1).Range("A" & Start)
End With
wbnew.Close
Set wbnew = Nothing
End If
Next
obApp.EnableEvents = True
obApp.ScreenUpdating = True
obApp.DisplayAlerts = True
MsgBox ("完成!")
End Sub
本來在匯總檔希望呈現的是
A B C D E F G H I
1
2
3
4 檔A 的 資料
5
6
7 檔B的資料
8
9
10 檔C的資料
11
依此類推
可是不知道為什麼
執行後只會有
A B C D E F G H I
1
2 檔C的資料
3
我沒有學過VBA,只是套用別人的
所以不知道問題出在哪裡
拜託了!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.248.66.32
※ 編輯: chopai0306 來自: 111.248.66.32 (10/12 15:58)
※ 編輯: chopai0306 來自: 111.248.66.32 (10/12 15:59)
推
10/12 19:17, , 1F
10/12 19:17, 1F
→
10/12 19:18, , 2F
10/12 19:18, 2F
→
10/12 19:18, , 3F
10/12 19:18, 3F
→
10/12 19:53, , 4F
10/12 19:53, 4F
→
10/12 19:54, , 5F
10/12 19:54, 5F
※ 編輯: chopai0306 來自: 220.133.30.227 (10/12 19:54)
Office 近期熱門文章
PTT數位生活區 即時熱門文章