Sub rt()
Dim strSQL As String
Set objconnection = CreateObject("ADODB.Connection")
DBQfile = ActiveWorkbook.FullName
Sheets("Sheet1").Activate
DBQsheet = ActiveSheet.Name
objconnection.Open "Provider=Microsoft.jet.OLEDB.4.0;" & _
"Data Source=" & DBQfile & ";" & _
"Extended Properties=""Excel 8.0;HDR=YES;"";"
DBQfile = ActiveWorkbook.FullName
selSQL = "Select * From [" & DBQsheet & "$]where (Number = 2 OR Number = 3 OR Number = 4) AND (Name = 'C' or Name = 'D' OR Name = 'E')"
strSQL = "INSERT INTO [Sheet2$] IN '" & DBQfile & "' 'Excel 8.0;' " & selSQL
MsgBox strSQL
objconnection.Execute strSQL
objconnection.Close
End Sub
|