人气 4342

Excel VBA 复制整列的内容到新的工作表的指定列 [复制链接]

精益人 2017-5-10 08:47:51
Excel VBA 复制整列的内容到新的工作表的指定列Sub复制整列的内容到新的工作表的指定列()
Dimi,arr
fori=1to6
WorkBooks.Open(i)
arr=ThisWorkBook.Sheets(1).Columns(i)
ActiveSheet.Columns(1)=arr
ActiveWorkBook.Closesavechange:=True
nexti
EndSubEXCEL将不同工作簿指定列的内容复制到一张工作表中Sub汇总()
cPath=ThisWorkbook.Path&"\"
myFile=Dir(cPath&"*.xlsx")
Application.ScreenUpdating=False
[a2].Resize(Cells(Rows.Count,1).End(xlUp).Row+10,11).ClearContents
DoWhilemyFile""
IfmyFileThisWorkbook.NameThen
Setwb=GetObject(cPath&myFile)
Withwb.Sheets(1)
nR=.Cells(Rows.Count,1).End(xlUp).Row
IfnR>1Thenarr=.[a2].Resize(nR-1,10)
EndWith
wb.CloseFalse
Setwb=Nothing
nR1=Cells(Rows.Count,1).End(xlUp).Row
Cells(nR1+1,1).Resize(nR-1,10)=arr
Cells(nR1+1,11).Resize(nR-1,1)=myFile
EndIf
myFile=Dir
Loop
Application.ScreenUpdating=True
MsgBox"汇总完毕!",vbInformation,"提示"
EndSub
您需要登录后才可以回帖 登录 | 立即注册

QQ|手机版|精益人 ( 沪ICP备19004111号-1 )|网站地图

GMT+8, 2024-12-22 22:58 , Processed in 0.500774 second(s), 20 queries .

Powered by Lean.ren X3.5 Licensed  © 2001-2030 LEAN.REN