gpt4 book ai didi

excel - vba 代码给我运行时错误 91 对象变量或未设置 block

转载 作者:行者123 更新时间:2023-12-03 03:16:50 36 4
gpt4 key购买 nike

请帮我看看为什么下面出现 91 代码错误。我将不胜感激。

  Dim ra As Range
Dim length As Integer

Set ra = Range("AE:AE").Find(What:="Dell EMC Maintenance Representative", LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
length = Len(ra)

If length < 40 Then
MsgBox ("Sales Rep. is missing!")
GoTo BEG

Else

转到请求

非常感谢

最佳答案

当您尝试对 ra 范围对象执行 len() 操作时,会发生错误。当您设置ra时,您必须考虑.Find方法找不到您的搜索条件的情况。发生这种情况时,ra 对象不包含任何内容,并且您无法对 nothing 执行 len() 操作。

在尝试检查长度之前,您应该通过检查以确保 ra 已设置为某些值来捕获此问题。像这样:

If ra Is Not Nothing Then
length = Len(ra)
Else
'handle this case (length = 0)
End If

关于excel - vba 代码给我运行时错误 91 对象变量或未设置 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52990470/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com