I am using a formula to indent text in column "D" based on values in column "C" and have been using it in VBA to format worksheets. It looks like this: =setindent(D2,C2). Until recently, it has worked well, but now it doesn't. It looks like Microsoft has started to force "implicit intersection operators" into formulas (adding the @: =@setindent(D2,C2). It seems to have neutered my formula where it returns "#Value!". If I open one of the cells with the formula in edit mode and then hit "Enter" it changes to a number and the formula works on the targeted cell text. How do I resolve this in VBA?
Here is the formula:
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
. . . and here is the VBA copying the formula
'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
Thanks,
Tim