Excel VBA - 范围不返回任何内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9417855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 15:19:39 来源:igfitidea点击:
Excel VBA - Range returns nothing
提问by CustomX
The following code will look for a cell containing 5/7 binnen 4h
and when it finds the cell it will copy the value of cell I on the same row to a different cell. Now there are a few cases when this text can't be found and I get an error. How could I handle this error?
以下代码将查找包含的单元格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
回答by assylias
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