excel - 有效的单元格引用停止运行
问题描述
我有一个正在运行的宏,它在使用范围引用的一行之后突然抛出错误“1004”,即使这个引用在这一点上工作得很好。请参阅下面的代码片段示例。
Option Explicit
Dim ws1 as Worksheet
Set ws1 = ThisWorkbook.Worksheets("Overview")
Dim PasteRange as Range
Set PasteRange = ws1.Range("AJ4:AM4") 'This is actually a variable range, but this is not important for this question
Dim CheckCell as Range
Dim ColCntr as Long
Dim ReviewCntr as Long
Dim LoopCntr as Long
ReviewCntr = ws1.Range("AA1").Value 'This cell only contains numerical values
For Each CheckCell in PasteRange
If LoopCntr = 0 Then
'A lot of code happens here, referencing CheckCell, all working
'flawlessly. Untill...
ColCntr = CheckCell.Column + ReviewCntr 'Final good working line
ElseIf LoopCntr <> 0 Then
CheckCell.Offset(0, BackSet2).Interior.ColorIndex = 3 '<-- error occurs
'Some More Code
End If
LoopCntr = LoopCntr + 1
Next CheckCell
突然上线出现对象定义错误
CheckCell.Offset(0, BackSet2).Interior.ColorIndex = 3
而且我不知道为什么或如何突然发生此错误,特别是因为它上面的行,引用仍然有效。通过 Debug DropDown 菜单编译项目不会产生错误。在单步执行代码时将鼠标悬停在Checkcell
上面时,它是有效的,并在弹出窗口中给出值和不给出的值。
代码到达特定行的那一刻,弹出窗口显示:
应用程序定义或对象定义的错误。
悬停BackSet2
在该行上会读取一个数值,这意味着偏移量正常工作。将鼠标悬停在CheckCell
位于此行之前的引用上仍会在弹出窗口中产生相关信息。
谁能告诉我这里的错误是什么?
解决方案
推荐阅读
- java - 在浏览器中打开时,S3 对象 url 不安全(ssl)
- node.js - 使用multer在节点js api的不同文件夹中发布多个文件上传字段
- javascript - Javascript / React 方括号的使用
- javascript - 在 .NET 中使用 WebBrowser,可以使用突变观察器来监视 DIV 更改吗?
- javascript - 在提交表单时停止非 Ajax 文件上传
- flutter - 我的 Flutter 项目没有运行(错误消息)
- java - 嵌套类的理解
- python - discord.py 命令连接到机器人
- macos - 如何在 MacOS 上键入 ascii 代码 127?
- python - python子进程调用变量