|
大神,你好,我弄了很久代码都无法达到5_多工作簿指定工作表,全部数据汇总的效果。
多个工作簿,但是SHEET123的命名都未必一致的,我要汇总多个工作簿的指定的SHEET1或者SHEET2,SHEET3的数据
sub 合并当前目录下所有工作簿的全部工作表()
dim mypath, myname, awbname
dim wb as workbook, wbn as string
dim g as long
dim num as long
dim box as string
application.screenupdating = false
mypath = activeworkbook.path
myname = dir(mypath & "\" & "*.xls")
awbname = activeworkbook.name
num = 0
do while myname <> ""
if myname <> awbname then
set wb = workbooks.open(mypath & "\" & myname)
num = num + 1
with workbooks(1).activesheet
.cells(.range("a65536").end(xlup).row + 2, 1) = left(myname, len(myname) - 4)
for g = 1 to sheets.count
wb.sheets(1).usedrange.copy .cells(.range("a65536").end(xlup).row + 1, 1)
next
wbn = wbn & chr(13) & wb.name
wb.close false
end with
end if
myname = dir
loop
range("a1").select
application.screenupdating = true
msgbox "共合并了" & num & "个工作薄下的全部工作表。如下:" & chr(13) & wbn, vbinformation, "提示"
end sub
例如以上代码,我运行后,却全部合并了sheet1的内容三次,但是我只要合并以此一次就够了。
请问大神指教和改编代码,谢谢谢谢 |
|