VBA代码覆盖单元格内的公式(Excel)

时间:2017-01-19 19:36:55

标签: vba excel-vba excel

'Make Schedule C Total Expenses line items always negative
    If Target.Address = "$I$25" Or Target.Address = "$L$25" Or Target.Address = "$O$25" Or Target.Address = "$R$25" _
    Or Target.Address = "$I$45" Or Target.Address = "$L$45" Or Target.Address = "$O$45" Or Target.Address = "$R$45" _
    Or Target.Address = "$I$65" Or Target.Address = "$L$65" Or Target.Address = "$O$65" Or Target.Address = "$R$65" _
    Or Target.Address = "$I$85" Or Target.Address = "$L$85" Or Target.Address = "$O$85" Or Target.Address = "$R$85" _
    Or Target.Address = "$I$105" Or Target.Address = "$L$105" Or Target.Address = "$O$105" Or Target.Address = "$R$105" Then
        If Target.Value > 0 Then
            Target.Value = 0 - Target.Value
        End If
    End If

我想将这些范围内的值转换为负值。但是,代码将覆盖单元格中的公式并将其替换为静态值。

我的公式是:

=IFERROR(IF(OR(F21=1,F21=2,F21=3,F21=4,F21=5),IF('PFS - Personal CF Report'!J$4=1040,INDEX(PFS1HY3!$A$3:$F$300,MATCH("C 28",PFS1HY3!$F$3:$F$300,0),5),0),0),0)

代码将替换静态值' 12560'的公式。我需要保留配方。任何帮助,将不胜感激。谢谢!

0 个答案:

没有答案