2012-02-23 200 views
1

以下代碼將查找包含5/7 binnen 4h的單元格,並且當它找到該單元格時,它會將同一行上的單元格I的值複製到不同的單元格。現在有幾種情況下,無法找到這個文本,我得到一個錯誤。我怎麼能處理這個錯誤?Excel VBA - 範圍不返回

Dim FoundRange As Range 
Set FoundRange = Cells.Find("5/7 binnen 4h") 
Range("I" & EmptyCell + 2).Value = Cells(FoundRange.Row, 9).Value 

回答

4
Dim FoundRange As Range 
Set FoundRange = Cells.Find("5/7 binnen 4h") 
If Not FoundRange Is Nothing Then 
    Range("I" & EmptyCell + 2).Value = Cells(FoundRange.Row, 9).Value 
Else 
    'you might want to do something if it is not found (msgbox...) 
End If 
+0

OMG很容易,如果你知道了吧!謝謝一堆! – CustomX 2012-02-23 17:22:35

+0

一到我家就會接受你的回答(延遲10分鐘) – CustomX 2012-02-23 17:22:58