※ 引述《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