作者icene (哎呀)
看板Visual_Basic
标题Re: [VBA ] 有上千笔资料比对~~要如何写才能提高执 …
时间Mon Jun 28 20:50:18 2010
※ 引述《evantw (安安小成)》之铭言:
: 我有个 Excel 内有上千笔资料要和资料库 .mdb 做比对
: 我是用 VBA 写法,用程式 Row 的
: 目前是一行一行的读取然後与资料库做比对
: 不过因为有上千笔~~
: 所以在比对程式 Row 时, Excel 感觉都快当掉了
: 而且比对时间也蛮长的~~(可能是电脑效能原因吧)
: 我目前所需求的是
: 有上千笔资料要与资料库中的 text 资料表栏位 A 做比对
: 如果在资料库中没有资料就 Show 出 No Data 的字
: 以下是我的写法~~
: For i = TextBox1.Text To Sheet1.Range("a1").End(xlDown).Row
: strsql = "select * from test where a like'" & .Cells(i, "A") & "'" '查询
: Set myrst = myCon.Execute(strsql)
: If myrst.EOF = True Then
: .Cells(i, "B") = "No Data"
: j = j + 1 '计算没有资料的笔数
: End If
: Next
: 因此~~想请教各位高手们有没有更快速的方法将上千笔资料与资料库快速做比对呢??
: 能否给的提示做法~~谢谢 ^^
**************************************************
match是excel内建函数 完全一样才会比对出 不同於like
select 一次就好 一直去select 会跑很慢
把excel资料写进access 用 join语法 也许会跑更快 但不太会写 @@
************************************************
dim arr()
strsql = "select * from test"
Set myrst = myCon.Execute(strsql)
redim arr(1 to myrst.recordsetcount)
do while myrst.EOF=true
i=i+1
arr(i)=myrst.field(i-1)
myrst.movenext
loop
on error resume next
For i = TextBox1.Text To Sheet1.Range("a1").End(xlDown).Row
str=.Cells(i, "A")
idx=application.match(str,arr,0)
if iserror(idx)=true then .Cells(i, "B") = "No Data"
next
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.134.105.197