优化这段代码:Range("订单明细!Extract").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _ Sheets("条件列表").Range("B1:B418"), CopyToRange:=Range("展示列表!Extract"), Unique _ :=True。在最后一行粘贴数据,并去除表头
时间: 2023-04-03 14:04:43 浏览: 172
ExcelVBA实例教程037:使用高级筛选获得不重复记录.pdf
这段代码可以优化为:
Dim wsExtract As Worksheet
Dim wsCriteria As Worksheet
Dim rngCriteria As Range
Dim rngExtract As Range
Dim rngCopyTo As Range
Set wsExtract = ThisWorkbook.Sheets("订单明细")
Set wsCriteria = ThisWorkbook.Sheets("条件列表")
Set rngCriteria = wsCriteria.Range("B1:B418")
Set rngExtract = wsExtract.Range("Extract")
Set rngCopyTo = ThisWorkbook.Sheets("展示列表").Range("Extract")
With rngExtract
.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=rngCriteria, CopyToRange:=rngCopyTo, Unique:=True
.Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).Copy
rngCopyTo.Offset(1, 0).PasteSpecial xlPasteValues
.Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).ClearContents
End With
这段代码会将数据复制到展示列表的Extract区域,并去除表头。
阅读全文