Option Explicit
Sub Copy()
On Error GoTo Handle
Dim cnn As Object, lsSQL As String, lrs As Object, FileFullName As String
Set cnn = CreateObject("ADODB.Connection")
Set lrs = CreateObject("ADODB.Recordset")
FileFullName = Application.ThisWorkbook.FullName
With cnn
If Val(Application.Version) < 12 Then
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileFullName & ";Extended Properties=""Excel 8.0;HDR=No"";"
Else
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FileFullName & ";Extended Properties=""Excel 12.0;HDR=No"";"
End If
.Open
End With
lsSQL = "Select f1,f2,f3,f4,'1:10' as col from [Data$A2:D600] where f1<11 union all select f1,f2,f3,f4,'91:100' as col from [Data$A2:D600] where f1>90"
lrs.Open lsSQL, cnn, 3, 1
Sheet1.[H2:K6000].ClearContents
Sheet1.Range("H2").CopyFromRecordset lrs
Set lrs = Nothing
cnn.Close: Set cnn = Nothing
Exit Sub
Handle:
MsgBox Err.Description
End Sub