+ Reply to Thread
Results 1 to 8 of 8

Why Does Custom Function in Name Get Called Twice?

  1. #1
    Registered User
    Join Date
    12-10-2010
    Location
    California
    MS-Off Ver
    Excel all versions from 5.0 (1993) to 365
    Posts
    38

    Why Does Custom Function in Name Get Called Twice?

    Hi

    My VBA code looks like this:

    Please Login or Register  to view this content.
    My worksheet has two defined names:

    TestCell refers to "=$E$7"

    TestRef refers to "=TestInfo(TestCell)"

    To duplicate the unexpected double-call, enter the following in the VBA immediate pane:
    Please Login or Register  to view this content.
    as expected, the address of TestCell is printed in the immediate pane once.

    However, the msgbox alert is unexpectedly displayed TWICE.

    Why?

    Note, the alert is displayed twice with or without setting EnableEvents and Calculation-- they make no difference.

    Thx.

    (also posted here)
    Last edited by johnywhy; 07-20-2014 at 06:59 PM.

  2. #2
    Forum Contributor mongoose36's Avatar
    Join Date
    06-10-2013
    Location
    Lincoln
    MS-Off Ver
    Excel 2013
    Posts
    389

    Re: Why Does Custom Function in Name Get Called Twice?

    It only does it once for me...do you have a worksheet change procedure that is perhaps causing the function to run again?
    If your questions has been answered to your satisfaction please don't forget to do the following:

    Add Reputation ... and ... Mark Thread as Solved

    Thanks,

    Ma 10:8b Freely you have received; freely give.

  3. #3
    Registered User
    Join Date
    12-10-2010
    Location
    California
    MS-Off Ver
    Excel all versions from 5.0 (1993) to 365
    Posts
    38

    Re: Why Does Custom Function in Name Get Called Twice?

    hrm... no worksheet change procedures.
    i'm on 2010, are you?
    Last edited by johnywhy; 07-21-2014 at 02:40 AM.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Why Does Custom Function in Name Get Called Twice?

    That UDF is run every time that TestRef is calculated.

    If I have two cells with the formula =TestRef, the UDF will run twice if I change E7, triggering a calculation of TestRef.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    12-10-2010
    Location
    California
    MS-Off Ver
    Excel all versions from 5.0 (1993) to 365
    Posts
    38

    Re: Why Does Custom Function in Name Get Called Twice?

    to be sure there are no lurking formulas or names, i duplicated the above in a brand new workbook. It's an .xlsb, Excel 2010.

    Still getting alert twice.

    @mikerickson, there are no formulas or data in any cells; only the defined names. As mentioned, i turned off events and set calculation to manual, so even if there were any event procs or sheet formulas (which there aren't), they would not get triggered anyway.

    thx

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,968

    Re: Why Does Custom Function in Name Get Called Twice?

    I see the same thing in 2010. I don't know why, but it is known that UDFs may be calculated more than once per workbook calculation.
    Everyone who confuses correlation and causation ends up dead.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Why Does Custom Function in Name Get Called Twice?

    A slight mod will show that A1 and TestCell are passed to it.

    Please Login or Register  to view this content.
    I assume that trying to read the names content causes it to be evaluated twice although it only returns the value once.
    Cheers
    Andy
    www.andypope.info

  8. #8
    Forum Contributor
    Join Date
    10-30-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2013
    Posts
    173

    Re: Why Does Custom Function in Name Get Called Twice?

    This is explained here
    Excel first tries to calculate named ranges. The first attempt to calculate TestRef fails because the R parameter is Dirty. TestRef is scheduled for re=calculation after the input parameter has been calculated. The sheet is then calculated and then TestRef is calculated again. So TestInfo is hit twice.

    This one is only hit once...
    Please Login or Register  to view this content.
    Last edited by coolblue; 07-21-2014 at 04:31 AM.

+ 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. Why is a custom function running when it is not called.
    By Rob K in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-02-2014, 07:37 AM
  2. [SOLVED] Userform code fails when the userform is called from a custom ribbon button
    By klonbeck in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2013, 03:00 PM
  3. Replies: 0
    Last Post: 02-21-2013, 08:28 AM
  4. Need to know what cell called the custom VBA function?
    By partyOfOne in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2005, 01:05 PM
  5. [SOLVED] Custom Function being called when it shouldn't.
    By Ron in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-18-2005, 04:06 PM

Tags for this Thread

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