我有一个超过10,000行的Excel文件。我想运行一个VBA脚本,该脚本删除列中以wordB
结尾的所有行reduce
。例如,如果我的专栏看起来像这样:
CostReduce
PriceReduce
ReducePrice
MaterialReduce
InfrastructureReduce
ReduceProfits
ReduceOverhead
我希望脚本可以运行并删除以结尾的单词的每一行Reduce
。因此输出将是:
ReducePrice
ReduceProfits
ReduceOverhead
我现在拥有的脚本会删除包含reduce单词的所有行,而且我不确定如何进行更改以使其能够执行我想要的操作。
Sub DeleteReduce()
Dim ContainWord As String
Dim i As Integer
i = 2
ContainWord = "reduce"
Do While Range("B" & i) <> ""
If Not Range("B" & i).Find(ContainWord) Is Nothing Then
Range("B" & i).EntireRow.Delete
Else
i = i + 1
End If
Loop
Range("B2").Select
End Sub
使用此Right
功能,对VB进行较小的更改:
Sub DeleteReduce()
Dim ContainWord As String
Dim i As Integer
i = 2
ContainWord = UCase("reduce")
Do While Range("B" & i) <> ""
If UCASE(right(Range("B" & i).value,len(ContainWord))) = ContainWord Then
Range("B" & i).EntireRow.Delete
Else
i = i + 1
End If
Loop
Range("B2").Select
End Sub
更新以消除区分大小写
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句