如何替换范围内大于零的数字?
我可以在给定范围内替换一个特定的单词或数字:
Sheet1.Columns("N").Replace What:="1", Replacement:="Good", LookAt:=xlWhole,
SearchOrder:=xlByRows, MatchCase:=False
现在,如果我想替换所有包含大于零的数字的东西1-1000000
,如使用循环语句,这会使宏运行缓慢。
我希望可以有这样的代码:
Sheet1.Columns("N").Replace What:=">0", Replacement:="Good", LookAt:=xlWhole,
SearchOrder:=xlByRows, MatchCase:=False`
您可以使用过滤器:
Sub tgr()
On Error Resume Next 'Prevents error if there are no cells with value >0
With Intersect(Sheet1.UsedRange, Sheet1.Columns("N"))
.AutoFilter 1, ">0"
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Value = "Good"
.AutoFilter
End With
On Error GoTo 0 'Remove the On Error Resume Next condition
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句