Sub Delete_with_Autofilter_More_Criteria()
Dim rng As Range
Dim cell As Range
Dim CriteriaRng As Range
Dim calcmode As Long
With Application
calcmode = .Calculation
.Calculation = xlCalculationmanual
.ScreenUpdating = False
End With
With Sheets("Sheet2")
Set CriteriaRng = .Range("A1",.Cells(Rows.Count,"A").End(xlUp))
End With
'Loop through the cells in the Criteria range
For Each cell In CriteriaRng
With Sheets("Sheet1")
'Firstly,remove the AutoFilter
.AutoFilterMode = False
'Apply the filter
.Range("A1:A" & .Rows.Count).AutoFilter Field:=1,Criteria1:=cell.Value
With .AutoFilter.Range
Set rng = Nothing
On Error Resume Next
Set rng = .Offset(1,0).Resize(.Rows.Count - 1,1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete
End With
'Remove the AutoFilter
.AutoFilterMode = False
End With
Next cell
With Application
.ScreenUpdating = True
.Calculation = calcmode
End With
End Sub
我有2张纸
Sheet1有一个库存清单;第1列包含股票行情收录器。大约有3000行数据
Sheet2在第1列中有一个股票行情清单(例如10个股票行情清单),并且此列表每月都会更改
我想做的是:
a)使用Sheet2第1列中的股票行情自动收录器在Sheet1第1列中查找相同的行情自动收录器
b)然后在Sheet1中为这些行情记录剪切整行
c)然后从特定的行号(例如行号2,500)开始在Sheet1中插入整个剪切行
d)当我插入整个剪切行时,我希望保留公式
感谢任何人都可以提供帮助,因为到目前为止我还没有找到解决方案-很多类似的情况,但以上没有。我是VBA的新手。我试图改写上面的代码,但无法执行步骤b)到d)。谢谢