+ Reply to Thread
Results 1 to 6 of 6

UDF to keep current value on FALSE from IF statement

  1. #1
    Registered User
    Join Date
    04-27-2020
    Location
    India
    MS-Off Ver
    2016
    Posts
    17

    UDF to keep current value on FALSE from IF statement

    Hi,

    I am using the below UDF to retain old value when if condition is false.

    Formula I am using is :
    =IF(AND(C9="Short",C10="Call",C11=9600),INDEX(OptionChain,MATCH(C11,OptionChain[Strike Price],0),9),CurrentValue())

    Code of CurrentValue() is :
    Function CurrentValue() As Variant
    CurrentValue = Application.Caller.Value
    If Val(CurrentValue) Then
    CurrentValue = Val(CurrentValue)
    ElseIf IsNumeric(CurrentValue) Then
    CurrentValue = Val(CurrentValue)
    End If
    End Function

    When IF statement condition is met, cell changes as per index search value but when condition is not met, value remains unchanged but I am getting message circular reference error.

    Kindly help me correct my UDF. Thanks in advance


    Rgds,
    Dhruv
    Attached Images Attached Images

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,634

    Re: UDF to keep current value on FALSE from IF statement

    See the hint in a yellow banner near the top of the page.
    Best Regards,

    Kaper

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,844

    Re: UDF to keep current value on FALSE from IF statement

    Even though you have tried to bury the circular reference inside of the UDF, Excel still knows that there is a circular reference. You either need to enable iteration (Excel options) or you need to eliminate the circular logic (at least in the spreadsheet).

    One advantage of enabling iteration, is that you can accomplish this without any VBA at all. =IF(condition,formula,reference to current cell). The main disadvantage to enabling iteration is, if you ever accidentally create a circular reference, you will no longer get the circular reference warning.

    If you decide not to enable iteration, then you need to do something to eliminate the circular logic from the spreadsheet. In this case, that probably means processing the If condition in VBA (maybe in a calculate event procedure).

    Please Login or Register  to view this content.
    Your choice how you would prefer to do this. We would be able to be more specific in our help if you provide a sample file as suggested.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    04-27-2020
    Location
    India
    MS-Off Ver
    2016
    Posts
    17

    Re: UDF to keep current value on FALSE from IF statement

    I have attached a sample worksheet. In case I change strike, at CMP there is a reference error cause I am using CurrentValue() UDF there.

    Thanks for your help …

    Rgds,
    Dhruv
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,844

    Re: UDF to keep current value on FALSE from IF statement

    Since I routinely operate with iteration enabled, your spreadsheet works just fine for me. I can replace the currentvlaue() UDF with F9, and the formula works just fine without needing VBA. Are you allowed to enable iteration? Are you comfortable with that option?

  6. #6
    Registered User
    Join Date
    04-27-2020
    Location
    India
    MS-Off Ver
    2016
    Posts
    17

    Re: UDF to keep current value on FALSE from IF statement

    Hi,

    Thanks for your response. I do know the option of enabling iteration but I thought it would be better if I could do it without enabling it as I would not know in case I add another formula with circular reference.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] IF statement with IF Statement as logical test, and output if false
    By wetbean in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-19-2018, 12:59 PM
  2. [SOLVED] Retain current cell value, if the next iteration returns false
    By sipa in forum Excel General
    Replies: 10
    Last Post: 11-07-2014, 03:11 PM
  3. [SOLVED] How can IIF Statement bring false statement?
    By jgomez in forum Access Tables & Databases
    Replies: 5
    Last Post: 07-19-2013, 06:16 PM
  4. Return True or False if date range falls within current month
    By kieran614 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-17-2013, 12:02 PM
  5. If statement, answer is false, hide false.
    By Mel B in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-07-2013, 06:36 PM
  6. If statement with a range and true/false statement
    By aarleblanc in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-20-2012, 06:34 PM
  7. If statement that does nothing when false
    By higherlimits in forum Excel General
    Replies: 1
    Last Post: 05-26-2006, 01:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1