如何使用相同的单元格公式值作为相同公式的输入?

时间:2015-10-31 03:44:06

标签: excel vba excel-vba

我需要解决这个问题:

在excel单元格A3上我使用自定义vba公式= SmoothTicker(A1,A2) 然后该函数必须使用它的A3单元输出作为输入值

Function SmoothTicker(Ticker As Integer, Increment As Integer)

   If (Ticker > SmoothTicker And Ticker - SmoothTicker > Increment) Then
        SmoothTicker = Ticker
    Else
        SmoothTicker = SmoothTicker
    End If

End Function

在这种情况下,我不能使用Smoothticker变量作为输入值 请帮忙!谢谢

2 个答案:

答案 0 :(得分:0)

这样做你想要的吗?

Private SmoothTickerValue As Integer

Function SmoothTicker(Ticker As Integer, Increment As Integer)

   If (Ticker > SmoothTickerValue And Ticker - SmoothTickerValue > Increment) Then
        SmoothTickerValue = Ticker
    End If
    SmoothTicker = SmoothTickerValue

End Function

执行此类操作的问题在于Excel不会按顺序计算连续单元格,并且除非输入发生更改,否则它也不会重新计算单元格 - 因此这种计算方式可能无法按预期工作。“ p>

答案 1 :(得分:0)

@Enigmativity的答案假设您想使用单元格的结果来计算另一个单元格。由于不太清楚你想要实现什么,我想另外,在计算单元格时,你要检查同一单元格的旧值。如果这是你想要的,你可以这样做:

Public Function SmoothTicker(ticker As Integer, inc As Integer) As Integer
   SmoothTicker = Application.ThisCell.Text
   If (ticker > SmoothTicker + inc) Then SmoothTicker = ticker
End Function