要知道的事情:
我想要完成的任务:
到目前为止我做了什么:
非常感谢您的帮助,如果我能提供更多有用的信息,请告诉我。我试图尽可能简洁但内容丰富。
Double1 = Now 'Delete Me 'Filter and delete dates before cutoff
Long1 = Application.CountA(.Columns(8))
Set Range1 = .Range(.Cells(1, 8), .Cells(Long1, 8))
With Range1
.AutoFilter Field:=1, Criteria1:="<" & DateSerial(2012, 10, 1) 'DateSerial uses (Year, Month, Day)
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
Double2 = Now 'Delete Me
答案 0 :(得分:0)
只要您不介意将结果复制到新工作表,使用ADO而不是自动过滤应该会给您更多的一致时间。
添加对&#34; Microsoft ActiveX Data Objects 2.8 Library&#34;的引用然后尝试这段代码(替换为适当的工作表和列名;记得在SELECT语句中的表名后面保留$符号):
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 12.0 Macro;HDR=YES;IMEX=1"";"
.Open
End With
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM [Sheet1$] WHERE [DateToCheck] >= #10/01/2012#", cn
Dim fld As ADODB.Field
Dim i As Integer
i = 0
With Worksheets("Sheet2")
.UsedRange.ClearContents
For Each fld In rs.Fields
i = i + 1
.Cells(1, i).Value = fld.Name
Next fld
.Cells(2, 1).CopyFromRecordset rs
.Cells.Columns.AutoFit
End With
rs.Close
cn.Close