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 |