简体   繁体   English

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

[英]How to use same cell formula value as input for the same formula?

I need to solve this: 我需要解决这个问题:

On the excel cell A3 I use the custom vba formula =SmoothTicker(A1,A2) Then the function must use it's A3 cell output as input value 在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

In that case I can't use Smoothticker variable as input value Please Help! 在这种情况下,我不能使用Smoothticker变量作为输入值,请帮助! thank you 谢谢

Does this do what you want? 这是您想要的吗?

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

The problem with doing this kind of thing is that Excel doesn't calculate contiguous cells in order and it also doesn't recalculate cells unless the inputs change - so this kind of calculation just simply may not work as expected. 进行此类操作的问题在于Excel不会按顺序计算连续的单元格,并且除非输入发生更改,否则它也不会重新计算单元格-因此,这种类型的计算可能根本无法按预期工作。

The answer of @Enigmativity supposes that you want to use the result of a cell to calculate another cell. @Enigmativity的答案假设您要使用一个单元格的结果来计算另一个单元格。 As it is not very clear what you want to achieve, I suppose alternatively that when calculating a cell you want to check against the old value of the same cell. 由于不清楚要实现的目标,我可以替代地假设在计算一个单元格时要对照同一单元格的旧值进行检查。 If that's what you want, you can do this: 如果这是您想要的,则可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM