當前位置:成語大全網 - 新華字典 - 如何編寫VBA轉置代碼?

如何編寫VBA轉置代碼?

sub?x()

dim?arr1,arr2,i,j,k

arr1=range("a1").currentregion

i=ubound(arr1)

j=ubound(arr1,2)

redim?arr2(1?to?(i-1)*j,?1?to?2)

k=1

for?i=2?to?ubound(arr1)

for?j=1?to?ubound(arr1,2)

arr2(k,1)=arr1(1,j)

arr2(k,2)=arr1(i,j)

next?j

next?i

range("j1").resize(ubound(arr2),ubound(arr2,2))=arr2

end?sub