1 回答
TA贡献1830条经验 获得超9个赞
mxbing1984
来自电脑网络类芝麻团 推荐于2016-02-13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | Sub Test() Dim cnn As ADODB.Connection Dim rs As ADODB.Recordset Set 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 = Nothing End Sub --这就是left join ,所以有 join 这个关键字 |
- 1 回答
- 0 关注
- 351 浏览
添加回答
举报