這個要用字典,寫過沒有,例子代碼:
dim?db(0?to?2),x,i,arr,id,nm'掃描數據
set?db(0)=createobject("scripting.dictionary")
for?each?x?in?array(1,2)
set?db(x)=createobject("scripting.dictionary")
arr=sheets(x).usedrange
for?i=1?to?ubound(arr)
id=trim(arr(i,1))
nm=trim(arr(i,2)
db(x)(id)=nm
db(0)(id)=true'總字典
next?i
next?x
'生成差異
aorkbooks.add
activesheet.cells(1,1).resize(1,4)=array("ID","姓名1","姓名2","比較")
i=2
for?each?id?in?db(0).Keys
cells(i,1)=id
if?db(1).Exists(id)?then?cells(i,2)=db(1)(id)
if?db(2).Exists(id)?then?cells(i,3)=db(2)(id)
cells(i,4)=iif(cells(i,2)=cells(i,3),"相同","不同")
i=i+1
next?id