Performance 过滤大于X的日期,然后清除过滤单元格的更快方法?
我有一个数据集,需要在其中查找范围内大于“X”的所有日期。然后我需要清除任何符合该条件的单元格的内容。我当前的代码循环遍历每一列,根据UserForm提供的变量“gDate”自动筛选,然后清除任何可见的单元格。数据集可以大到54列和1000多行 我还是VBA新手,我知道创建循环可能不是最优的。也就是说,有没有更快、更有效的方法来完成我的任务Performance 过滤大于X的日期,然后清除过滤单元格的更快方法?,performance,excel,date,autofilter,vba,Performance,Excel,Date,Autofilter,Vba,我有一个数据集,需要在其中查找范围内大于“X”的所有日期。然后我需要清除任何符合该条件的单元格的内容。我当前的代码循环遍历每一列,根据UserForm提供的变量“gDate”自动筛选,然后清除任何可见的单元格。数据集可以大到54列和1000多行 我还是VBA新手,我知道创建循环可能不是最优的。也就是说,有没有更快、更有效的方法来完成我的任务 Sub FilterDates() Dim ws2 As Worksheet Dim rng As Range Dim gDate As Date Dim
Sub FilterDates()
Dim ws2 As Worksheet
Dim rng As Range
Dim gDate As Date
Dim LastRow2 As Long, LastCol2 As Long
Set ws2 = Sheets("Sheet2")
LastRow2 = ws2.Cells(Rows.count, 1).End(xlUp).row
LastCol2 = ws2.Cells(1, Columns.count).End(xlToLeft).Column
gDate = Sheets("UFinput").Cells(2, 1)
Set rng = ws2.Range(Cells(1, 1), Cells(LastRow2, LastCol2))
'Loops through columns filtering dates > gDate then clears
With rng
On Error Resume Next
Dim iLoop As Long
For iLoop = 5 To LastCol2
.AutoFilter Field:=iLoop, Criteria1:=">" & gDate
ws2.Range(Cells(2, iLoop), Cells(LastRow2, iLoop)).SpecialCells(xlCellTypeVisible).ClearContents
.AutoFilter Field:=iLoop
Next iLoop
End With
ws2.AutoFilterMode = False
End Sub
Automatically Sort Data in Alphabetical Order using Formula.
Dynamic Excel Filter – Extract Data as you Type.
Creating Multiple Drop-down Lists in Excel without Repetition.
To switch to manual mode, go to Formula Tab –> Calculation Options –> Manual (press F9 key to recalculate)
慢速Excel电子表格-手动计算
10使用更快的公式和技术
Excel为您提供了许多公式和公式组合来完成相同的工作。最好确定并使用最快的
以下是几个例子:
Use IFERROR instead of IF and ISERROR combo (unless you are using Excel 2003 or earlier, which does not have IFERROR).
Use MAX(A1,0) instead do IF(A1>0,A1,0) – This is a cool tip that I learned from Mr. Excel aka Bill Jelen. His research shows that MAX option is 40% faster than IF option (and I am ready to take this stat on his face value).
Use the INDEX/MATCH combo, instead of VLOOKUP – This may raise a lot of eyebrows, but the truth is, there is no way VLOOKUP can be faster if you have 100’s of columns of data. The world is moving towards INDEX/MATCH, and you should make the shift too.
[If you are still confused about what to use, here is a head-on-head comparison of VLOOKUP Vs. INDEX/MATCH].
Use — (double negatives) to convert TRUE’s and FALSE’s to 1’s and 0’s (instead of multiplying it by 1 or adding 0 to it). The speed improvement is noticeable in large data sets.
这是一份详尽的清单吗?绝对不是。这些都是我认为值得分享的好东西,作为一个起点。另外值得注意的是:屏幕更新、EnableEvents等都已关闭。您是否希望在此日期筛选多个列?如果不是,您根本不需要这个循环。只需根据正确的列自动筛选工作表即可。是的,有多个列(列(5)到“LastCol2”),每一列都独立于其他列。需要清除整个范围内的任何日期>“gDate”(例如E2:BB1000)。