我正在尝试编写宏来自动将所选范围内的单元格分类为“输入”、“输出”和“计算”单元格。当 rcell 没有先例或依赖项时,对于包含 rCell.Precedents.Count 或 rCell.Dependents.Count 的语句,我收到“运行时错误'1004':未找到单元格”。我试过了
IsEmpty(rCell.Dependents)
但我仍然遇到同样的错误。
Private Sub test_v05()
ActiveSheet.Cells.Interior.ColorIndex = xlColorIndexNone
Dim Target As Range, rCell As Range
Set Target = Sheets("Sheet1").Range("A1:C10")
For Each rCell In Target.Cells
If IsEmpty(rCell.Value) = True Then GoTo AllDone:
If rCell.Precedents.Count = 0 And rCell.Dependents.Count > 0 Then
rCell.Style = "Input"
GoTo AllDone:
End If
If rCell.HasFormula And rCell.Dependents.Count = 0 Then
rCell.Style = "Output"
GoTo AllDone:
End If
If rCell.Precedents.Count > 0 And rCell.Dependents.Count > 0 Then
rCell.Style = "Calculation"
End If
AllDone:
Next rCell
End Sub
在跟踪没有依赖项或单元格的先例时处理错误的最佳方法是什么?
最佳答案
考虑:
Sub Dependental()
Dim n As Long
n = 0
On Error Resume Next
n = Cells.Precedents.Count
On Error GoTo 0
MsgBox "there are " & n & " cells with dependents"
End Sub
关于vba - excel中没有依赖的单元格的 "cell.dependents.count"处理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35866979/