A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Sub Test4()
Dim Conn As Object, Rst As Object
Dim strConn As String, strSQL As String
Dim i As Integer, PathStr As String
Set Conn = CreateObject("ADODB.Connection")
Set Rst = CreateObject("ADODB.Recordset")
PathStr = ThisWorkbook.FullName '
Select Case Application.Version \* 1 '
Case Is <= 11
strConn = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=excel 8.0;Data source=" & PathStr
Case Is >= 12
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PathStr & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
End Select
'here set your sql to select rows not contain cText in column cText\_col
strSQL = "select \* [sheet1$] where [cTxt\_column\_first] not like '%" & cText & %"''
Conn.Open strConn '
Set Rst = Conn.Execute(strSQL) '
With Sheet3
.Cells.Clear
For i = 0 To Rst.Fields.Count - 1 '
.Cells(1, i + 1) = Rst.Fields(i).Name
Next i
.Range("A2").CopyFromRecordset Rst
.Cells.EntireColumn.AutoFit '
.Cells.EntireColumn.AutoFit '
End With
Rst.Close '
Conn.Close
Set Conn = Nothing
Set Rst = Nothing
End Sub