|
- Sub zz()
- Dim a, b, c, d, wb As Workbook, ar, n%, t As Boolean, r&, s$, rc%(1)
- Application.ScreenUpdating = 0
- Set wb = ThisWorkbook
- With Sheets("setting")
- a = .[a3:b3].Value '建立 a 數組
- b = .[c3:d3].Value ''建立 b 數組
- c = Sheets(b(1, 1)).Range(b(1, 2)).Column - 1 '變量取列號
- c = Sheets(b(1, 1)).Range(b(1, 2)).Offset(1).End(2).Column - c '變量取列號
- bb = Sheets(b(1, 1)).Range(b(1, 2)).Resize(1, c).Value '建立航空(1-?)的數組
- c = .Range("e3:f" & .[f65536].End(3).Row).Value '建立 c 數組
- d = .Range("g3:h" & .[h65536].End(3).Row).Value '建立 d 數組
- End With
- For i = 1 To UBound(bb, 2) '循環航空(1-?)
- wb.Sheets(a(1, 1)).Copy 'Copy 表一
- Range(a(1, 2)).Value = Range(a(1, 2)).Value & bb(1, i)
- With ActiveWorkbook
- For j = 1 To UBound(c) '循環提取資料到相對頁的頁名
- rc(0) = Range(c(j, 2)).Row: rc(1) = Range(c(j, 2)).Column + i - 1 '提取儲存格的行列號
- r = wb.Sheets(c(j, 1)).Cells(65536, rc(1)).End(3).Row '提取最下儲存格的列號
- ar = wb.Sheets(c(j, 1)).Cells(rc(0), rc(1)).Resize(r - rc(0) + 1) '建立 ar 數組
- wb.Sheets(d(j, 1)).Copy After:=.Sheets(.Sheets.Count) 'Copy d 數組中的頁
- rc(0) = Range(d(j, 2)).Row: rc(1) = Range(d(j, 2)).Column '提取儲存格的行列號
- Cells(rc(0), rc(1)).Resize(UBound(ar)).NumberFormat = 0 '將範圍格式
- Cells(rc(0), rc(1)).Resize(UBound(ar)) = ar '將資料寫入
- Next
- .Sheets(1).Activate
- .SaveAs bb(1, i) '存檔
- .Close
- s = s & Chr(10) & bb(1, i)
- End With
- Next
- Set wb = Nothing
- Application.ScreenUpdating = 1
- MsgBox i - 1 & " files saved as : " & s
- End Sub
复制代码
|
|