Excel VBA - 范围不返回任何内容

时间:2012-02-23 17:18:17

标签: vba excel-vba excel

以下代码将查找包含5/7 binnen 4h的单元格,当它找到单元格时,它会将同一行中单元格I的值复制到另一个单元格。现在有一些情况下无法找到此文本,我收到错误。我怎么能处理这个错误?

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

1 个答案:

答案 0 :(得分:5)

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