【发布时间】:2021-01-08 17:52:11
【问题描述】:
我使用公式根据“C”列中的值缩进“D”列中的文本,并一直在 VBA 中使用它来格式化工作表。它看起来像这样:=setindent(D2,C2)。直到最近,它运行良好,但现在却不行。看起来微软已经开始将“隐式交集运算符”强制添加到公式中(添加@:=@setindent(D2,C2)。它似乎已经在返回“#Value!”的地方取消了我的公式。如果我打开其中一个带有公式的单元格处于编辑模式,然后按“Enter”,它会变为数字,公式适用于目标单元格文本。如何在 VBA 中解决这个问题?
公式如下:
Function SetIndent(z As Range, ByVal Level As Long) As Variant
Dim celldent As Range
SetIndent = IIf(Level < 0, "Min is 0!", IIf(Level > 10, "Max is 10!", Level))
If Level < 0 Then Level = 0 Else If Level > 10 Then Level = 10
For Each celldent In z
With celldent
If Level - .IndentLevel Then .InsertIndent Level - .IndentLevel
End With
Next celldent
End Function
。 . .这是复制公式的VBA
'Format the Name (Column D) to indent per the Outline Level value in Column C
'See Module 16 for the Function: SetIndent
Range("AB2").Select
ActiveCell.Formula = "=SetIndent(D2,C2)"
Range("AB2").Copy Range("$AB$3:AB" & lastRow)
' Range("$AB2:AB" & lastRow).Clear
谢谢,
提姆
【问题讨论】:
-
或许可以试试
Formula2 -
仅供参考,请参阅 How to add dynamic array formula 的 隐式交集运算符的帖子
-
TM 和 Rory,感谢您指出 Formula2 选项和有关 IIO 的信息。我尝试了 Formula2,但仍然得到相同的结果:#VALUE!直到我编辑单元格。公式在我手动复制粘贴时有效,所以我不知道当相同的VBA操作不起作用时会发生什么。?