求vba一个文件数据复制到另一个文件

2022-03-28 娱乐 83阅读
SubTestMoveData()
Dimwsh1AsWorksheet
Dimwsh2AsWorksheet
Setwsh1=Application.Workbooks("A.xlsx").Sheets("Sheet1")
Setwsh2=Application.Workbooks("B.xlsx").Sheets("Sheet1")

DimaLastAsLong
aLast=wsh1.Range("B:B").Find("*",,,,,xlPrevious).Row
Dimarr1()
arr1=wsh1.Range("B2").Resize(aLast-2+1,1)
Dimarr2()
arr2=arr1
DimxAsLong
DimyAsLong
y=1
Forx=1ToUBound(arr1,1)
Ifarr1(x,1)="yes"Then
arr2(y,1)=arr1(x,1)
y=y+1
EndIf
Next
arr2=Application.WorksheetFunction.Transpose(arr2)
ReDimPreservearr2(1Toy-1)
arr2=Application.WorksheetFunction.Transpose(arr2)
wsh2.Range("B21").Resize(y-1,1)=arr2
EndSub
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com