當前位置:成語大全網 - 新華字典 - VBA 將Excel中符合條件的幾行數據合並成壹行,並將這幾行某壹列數據匯總放到第壹行,刪除其他行

VBA 將Excel中符合條件的幾行數據合並成壹行,並將這幾行某壹列數據匯總放到第壹行,刪除其他行

妳這個問題用字典最方便了

sub test ()

dim arr,brr(),x&,i&,d as object,str1$

set d=createojbedt("scripting.dictionary")

arr=range("A1:C"& range("A65536").end(xlup).row)

redim brr(1 to 3,1 to 1)

for x=1 to ubound(arr)

str1=arr(x,2) & "|" & arr(x,3)

if not d.exists(str1) then

i=i+1

d(str1)=i

redim preserve brr(1 to 3,1 to i)

brr(2,i)=arr(x,2)

brr(3,i)=arr(x,3)

end if

brr(1,d(str1))=brr(1,d(str1))+arr(x,1)

next x

range("E1").resize(ubound(brr,2),3)=application.transpose(brr)'妳要統計到哪就把前面的單元格地址改成妳要寫到的地方即可

end sub