慕标琳琳
mxbing1984 来自电脑网络类芝麻团 推荐于2016-02-131234567891011121314151617181920212223Sub Test()Dim cnn As ADODB.ConnectionDim rs As ADODB.RecordsetSet cnn = New ADODB.Connection With Sheet3 .Cells.Clear With cnn .Provider = "microsoft.jet.oledb.4.0" .ConnectionString = "Extended Properties=Excel 5.0;" + "Data Source=" + ThisWorkbook.FullName .Open End With Set rs = New ADODB.Recordset Sql = "select A.*,B.name,B.money From [Sheet1$] A left join [Sheet2$] B on A.id=B.id" rs.Open Sql, cnn, adOpenKeyset, adLockBatchOptimistic R = .Range("A65536").End(xlUp).Row - 1 .Range("A" & R + 1).CopyFromRecordset rs End With rs.Close cnn.Close Set rs = Nothing Set cnn = NothingEnd Sub--这就是left join ,所以有 join 这个关键字