vba-excel <> 的含义(尖括号或大于和小于符号)
我正在使用 VBA Excel 中的查找函数,因此当遇到问题时,我从 Excel 提供的帮助中提取了一些示例代码。我拿了他们的代码来说明基本的 查找函数并将其粘贴到宏中。运行宏时,我收到“运行时错误‘91’”,并且调试器突出显示包含尖括号 <> 的代码行。这些是我无法理解的代码部分。
谁能告诉我这些括号代表什么?
Sub exampleFindReplace()
With Worksheets(1).Range("a1:a500")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
<>
运算符表示c.Address
不等于firstAddress
。在 C 风格语言中,这相当于
c.Address != firstAddress
。旁注,我认为您收到错误 91(未设置对象变量或 With 块变量。),因为代码行
Loop While Not c Is Nothing And c.Address <>即使第一个条件 (
While Not C Is Nothing
) 的计算结果为错误的。因此,对 c.Address 的调用将引发异常。尝试编写这样的代码,因为它不会允许这种情况发生:
The
<>
operator meansc.Address
Is Not Equal TofirstAddress
.In a C-style language this would be equivalent to
c.Address != firstAddress
.Side note, I think you are getting error 91 (Object variable or With block variable not set.) because the line of code
Loop While Not c Is Nothing And c.Address <> firstAddress
will always try to execute the second condition (c.Address <> firstAddress
) even if the first (While Not C Is Nothing
) evaluates to false. Thus the call on c.Address will raise the exception.Try writing the code like this as it will not allow that to happen: