public sub quickconsolidatemethod()'宣告變數
dim wb as workbook, openwb as workbook
dim sht as worksheet, onesht as worksheet
dim rng as range, onerng as range, rangeaddress as string
const sheet_index = 1
const range_address = "c5:l17"
dim firstcell as range
dim arr() as string
redim arr(1 to 1)
dim folderpath, filename, fileindex
'設定物件
set sht = wb.activesheet
set rng = sht.range(range_address)
set firstcell = rng.cells(1, 1) '合計結果輸出位置的左上角
rangeaddress = rng.address(referencestyle:=xlr1c1) '選用指定格式的單元格位址
folderpath = wb.path & "\各部門\" '各部門工作簿資料夾
fileindex = 0
filename = dir(folderpath & "*.xls*")
do while filename <> ""
fileindex = fileindex + 1
redim preserve arr(1 to fileindex)
set onesht = openwb.worksheets(sheet_index)
arr(fileindex) = "'" & folderpath & "[" & filename & "]" & onesht.name & "'!" & rangeaddress '構造引用位址
openwb.close false '關閉檔案
filename = dir
loop
'執行合併計算方法
firstcell.consolidate sources:=arr, function:=xlsum, toprow:=false, leftcolumn:=false, createlinks:=false
'釋放物件
set wb = nothing: set sht = nothing
set rng = nothing: set openwb = nothing
set onesht = nothing
end sub
vba操作多工作分表合併
彙總分表資訊至一張總表,是資料分析相關工作中常遇到的事情,一般辦法是手動複製每個分表再貼上到彙總表裡,但利用以下vba 可以在excel中自動實現 執行該步驟的目的是確保分表的順序正確,便於之後進行合併時的for迴圈 sub check dim check as worksheet set chec...
PHPExcel 多工作表 匯入
引數初始化 filepath if files file error 0 filepath files file tmp name 建立reader物件 this load library phpexcel phpreader new phpexcel reader excel2007 if php...
Excel多工作表頁碼連續設定
列印excel 2002工作表之前需要設定頁碼,如果多張工作表的頁碼必須連續排列,就得採用一些特殊的頁碼設定技巧。假設有名為sheet1 sheet2和sheet3的三張工作表,分別可以列印2 3 5頁,並且列印時每個工作表的內容要連線在一起。可以按以下方法設定頁碼 首先開啟工作表sheet1,單擊...