|
本帖最后由 wxxydl 于 2020-1-20 18:19 编辑
Private Sub aatest()
Dim sh1 As Worksheet
Dim i As Integer, j As Integer
Dim filename, conn, rs, table As Variant
Dim arr
filename = ThisWorkbook.FullName
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("adodb.Recordset")
conn.Open "Provider=Microsoft.jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
table = "[数据源$]"
SQL = ""
SQL = SQL & "select 编号 from " & table & " where"
Set sh1 = ThisWorkbook.Sheets("查找模板")
arr = sh1.[d1:p2]
For i = 1 To UBound(arr, 2)
If arr(2, i) <> "" Then
'If Application.WorksheetFunction.IsNumber(arr(2, i)) Then
's = s & " and " & arr(1, i) & "=" & arr(2, i)
'Else
s = s & " and " & arr(1, i) & "='" & arr(2, i) & "'"
'End If
End If
Next
s = Right(s, Len(s) - 4)
SQL = SQL & s
' bb = conn.Execute(SQL).getrows
' rs.Open SQL, conn, 3, 1
sh1.Cells(2, 1).CopyFromRecordset conn.Execute(SQL)
Set rs = Nothing
conn.Close
Set conn = Nothing
End Sub
|
评分
-
1
查看全部评分
-
|