|
sql肯定是可以实现的。不过这种运用事件的做法,sql效率不高。
写个你可以参考一下。
Sub 单条查询()
Dim cnn As Object
Dim Sql As String, i, s$
Set cnn = CreateObject("ADODB.CONNECTION")
For i = 2 To 4
s = s & Cells(1, i) & "='" & Cells(3, i) & "' AND "
Next
s = Left(s, Len(s) - 4)
cnn.Open "Provider=Microsoft.Jet.OleDb.4.0;Extended Properties='Excel 8.0;HDR=YES'; Data Source=" & ThisWorkbook.FullName
Sql = "select 型号,产地,订货周期,单位 from [数据区$A1:G] WHERE " & s
[E3:H3] = ""
[E3].CopyFromRecordset cnn.Execute(Sql)
cnn.Close: Set cnn = Nothing
End Sub
Sub 批量查询()
Dim cnn As Object
Dim Sql As String, i%, s$
Set cnn = CreateObject("ADODB.CONNECTION")
i = [b9999].End(3).Row
cnn.Open "Provider=Microsoft.Jet.OleDb.4.0;Extended Properties='Excel 8.0;HDR=YES'; Data Source=" & ThisWorkbook.FullName
Sql = "select B.型号,B.产地,B.订货周期,B.单位 from [查找区$b1:G" & i & "] A left join [数据区$A1:G] B ON A.类型=B.类型 AND A.规格=B.规格 AND A.品牌=B.品牌 where B.型号 is not null"
[E3:H6] = ""
[E3].CopyFromRecordset cnn.Execute(Sql)
cnn.Close: Set cnn = Nothing
End Sub
|
评分
-
1
查看全部评分
-
|