我有一个电子表格,用于连接我的mySQL数据库并对该数据库进行更改。我认为我在系统中检查重复项的方式是非常低效的,但我很难想到一种更有效的方法。按项目逐个进行所需的时间并不长,只有100个项目,但它很长,有50,000个项目,而且我试图找到缩短时间的方法过程需要。
'/ Define last row with data in it
lastRow = Range("C" & Rows.Count).End(xlUp).Row
'/ go through each row, line by line, to check if this part number is in the system
For c = 5 To lastRow Step 1
'/ Based on user input, runs a SELECT query to see if the part number in question is already in the table they're trying to upload into
SQLStr = "SELECT quotePartNumber FROM " & table & " where (quotePartNumber, `debitNumber) IN (('" & partNumber & "', '" & debitNum & "')) LIMIT 1"`
rs.Open SQLStr, conn, adOpenStatic
' Dump to spreadsheet
With Worksheets("DATA").Range("N28:N28")
.ClearContents
'/ copy SQL output to cell N28, then check if an output exists. If the part exists in the table already, a part number will fill N28, if the part doesn't exist, N28 will be blank.
.CopyFromRecordset rs
End With
'/ If the part already exists, delete this part number from the spreadsheet.
pnCheck = Range("N28").Value
If pnCheck <> "" Then
Range(Cells(c, 1), Cells(c, 11)).Select
Selection.Delete Shift:=xlUp
deleted = deleted + 1
c = c - 1
End If
'/ reset rs for the next run through
rs.Close
Set rs = Nothing
Range("N28") = ""
debit = False
next c
所以基本上,我浏览电子表格中的每一行,检查我的表中是否已经存在该部分,如果存在,我将从电子表格中删除该行。一旦列表被削减到表中已经没有的内容,我就上传它(这里没有显示代码......)
是否有更有效的方法可以检查表格中的5,000到100,000个零件号,而不是逐行检查?