當前位置:成語大全網 - 新華字典 - 如何在excel中用宏(VBA)實現VLOOKUP的功能

如何在excel中用宏(VBA)實現VLOOKUP的功能

sub?test()

dim?dic?as?object,mAry,mRow?as?long,

set?dic=createobject("scripting.dictionary")

with?workSheets("數據")

mrow=.cells(.rows.count,1).end(3).row

mAry=.[a2].resize(mrow-1,2)

end?with

for?i=1?to?ubound(mary,1)

dic(""?&?mary(i,1))=mary(i,2)

next?i

with?worksheets("求解表")

mrow=.cells(.rows.count,1).end(3).row

mAry=.[a2].resize(mrow-1,1)

for?i=1?to?ubound(mary,1)

if?dic.exists(""?&?mary(i,1))?then

mary(i,1)=dic.exists(""?&?mary(i,1))

else

mary(i,1)="NO?find!"

end?if

next?i

.[b2].resize(ubound(mary,1),1)=mary

end?with

end?sub