对我的代码做一些小改动

对我的代码做一些小改动

我一直在使用下面的代码,但希望有人能帮我做一点小改动。我需要将以下代码行中的“15”改为“Set Found = SearchCell.Find(What:=15, Lookat:=xlPart)”,以查找任何具有 000.00 格式的数字。

当前使用的代码;

Option Explicit

Sub Found()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet2")
Dim SearchRange As Range, SearchCell, Found As Range
Set SearchRange = ws.Range("F1:F20")
For Each SearchCell In SearchRange
    Set Found = SearchCell.Find(What:=15, Lookat:=xlPart)
    If Not Found Is Nothing Then
        Found.Interior.Color = vbRed
    End If
    Set Found = Nothing
Next SearchCell
End Sub

答案1

这里是稍微改变的代码:

Sub Found()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet2")
Dim SearchRange As Range, SearchCell As Range
Set SearchRange = ws.Range("F1:F20")
For Each SearchCell In SearchRange
    If SearchCell.NumberFormat = "000.00" Then
        SearchCell.Interior.Color = vbRed
    End If
Next SearchCell
End Sub

相关内容