|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
调整一下顺序,先去重,再连接。
Sub 查询()
Dim cnn As Object
Dim sqa As String, r%, sql As String
Set cnn = CreateObject("ADODB.CONNECTION")
r = [g13].End(3).Row
If r = 4 Then Exit Sub
cnn.Open "Provider=Microsoft.ACE.OleDb.12.0;Extended Properties='Excel 12.0;HDR=YES'; Data Source=" & ThisWorkbook.FullName
sqa = "select distinct * from [sheet2$a1:e8] where 料号 is not null"
sql = "select 料号,品名,规格,单位 from [sheet1$g4:g" & r & "] a left join (" & sqa & ") b on a.批号=b.批号"
[a5:d12] = ""
[a5].CopyFromRecordset cnn.Execute(sql)
cnn.Close: Set cnn = Nothing
End Sub |
评分
-
1
查看全部评分
-
|