我正在使用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 <> firstAddressEnd IfEnd WithEnd Sub 最佳答案 <>运算符表示c.Address不等于firstAddress。在C风格的语言中,这等效于c.Address != firstAddress。旁注,我认为您会遇到错误91(未设置对象变量或With块变量。),因为代码行Loop While Not c Is Nothing And c.Address <> firstAddress将始终尝试执行第二个条件(c.Address <> firstAddress),即使第一个条件(While Not C Is Nothing )计算为假。因此,对c.Address的调用将引发异常。尝试编写这样的代码,因为它不允许发生这种情况: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) If c Is Nothing Then Exit Do Loop While c.Address <> firstAddressEnd IfEnd WithEnd Sub关于excel-vba - vba-excel的<>含义(尖括号或大于和小于符号),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6538079/
10-10 19:00