Định nghĩa thế nào là một dòng?
Sub test()
Dim cn As Object, rst As Object
Dim mySQL As String
Set cn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
If Val(Application.Version) < 12 Then
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.FullName & ";Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"";"
Else
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & ";Extended Properties=""Excel 12.0;HDR=YES;IMEX=1"";"
End If
.Open
End With
mySQL = "select * from BC_TONG where C5 = '" & (Sheet6.Range("S2")) & "'" & _
"and C6 = '" & (Sheet6.Range("T2")) & "'" & _
"and C7 = '" & (Sheet6.Range("U2")) & "'" & _
"and C8*1 = '" & (Sheet6.Range("V2") * 1) & "'" & _
"and C9 = '" & (Sheet6.Range("W2")) & "'" & _
"and C10 = '" & (Sheet6.Range("X2")) & "'" & _
"and C11 = '" & (Sheet6.Range("Y2")) & "' "
Set rst = cn.Execute(mySQL)
Range("o3").CopyFromRecordset rst
' tim dong chua mySQL trong du lieu
Dim i As Long
'i = Sheet6.Range("A1:M20000").Find("rst").Row
Set rst = Nothing: Set cn = Nothing
End Sub
Bác xem giúp