AlvinArg
AlvinArg

Reputation: 1

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

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! thank you

Upvotes: 0

Views: 691

Answers (2)

A.S.H
A.S.H

Reputation: 29332

The answer of @Enigmativity supposes that you want to use the result of a cell to calculate another cell. 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

Upvotes: 1

Enigmativity
Enigmativity

Reputation: 117037

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.

Upvotes: 0

Related Questions