2013-11-04 133 views
0

我有以下代碼來查找單元格是否具有特定值「0.0」。但是,我並沒有意識到,如果10.0是一個價值,那麼該計劃也會把它撿起來。我如何修改代碼來準確地只提取0.0?如何使用VBA識別單元格是否具有特定的數值

Sub ReformatDeplete() 

Dim SrchRng3 As Range 
Dim c3 As Range, f As String 

Set SrchRng3 = Worksheets("Melanoma").Range("M4", Worksheets("Melanoma").Range("M65536").End(xlUp)) 
Set c3 = SrchRng3.Find("0.0", LookIn:=xlValues) 
If Not c3 Is Nothing Then 
    f = c3.Address 
    Do 
     With Worksheets("Melanoma").Range("A" & c3.Row & ":M" & c3.Row) 
      .Font.ColorIndex = 1 
      .Interior.ColorIndex = 16 
     End With 
     Set c3 = SrchRng3.FindNext(c3) 
    Loop While c3.Address <> f 
End If 

End Sub 

任何意見,將不勝感激。

感謝先進!

回答

4

您正在尋找.Find函數的Lookat參數。

Set c3 = SrchRng3.Find("0.0", LookIn:=xlValues, Lookat:=xlWhole) 

有此說法,xlPartxlWhole兩個常量。如您所注意到的,如果未指定,則該功能默認爲xlPart

要了解更多關於.Find功能,check out this link.

+0

+1回答的很好的解釋。 –

+0

謝謝!像魅力一樣工作! – crazian

+0

不客氣!很高興幫助! – ARich

相關問題