+ Reply to Thread
Results 1 to 9 of 9

UDF - Auto refresh issue

  1. #1
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Question UDF - Auto refresh issue

    Greetings,

    I have a UDF that uses data from one sheet to display result in a second sheet. I added the “Application.Volatile” statement so that the result in the second sheet is automatically refreshed if data in the first sheet changes.

    However, I have now noticed that if I run any macro in the workbook, the UDF gives “#VALUE!”. I have to manually click in the cell and hit the ENTER button in order to get the result.

    A solution offered was to add the line
    Please Login or Register  to view this content.
    before the "End Sub" to calculate the workbook before the macro ends.

    However, I have several macros in the my workbook and was wondering if something can be done at the workbook level instead of the adding the “calculate” line in every macro?

    The UDF is

    Please Login or Register  to view this content.
    Many thanks
    Asha

    Last edited by asha3010; 06-10-2010 at 09:43 AM.

  2. #2
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: UDF - Auto refresh issue

    Asha;

    I didn't look at your UDF(), but this will calculate your entire workbook everytime you change anything in the workbook
    Please Login or Register  to view this content.
    Or if you only want to calculate the sheet that was changed:
    Please Login or Register  to view this content.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  3. #3
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: UDF - Auto refresh issue

    Hi Foxguy,

    Thanks for your reply.

    Sorry but am not sure where to place this code - in the private module of "ThisWorkbook"?

    Asha

  4. #4
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: UDF - Auto refresh issue

    Correct, Any Subs that have names starting with "Workbook_...." go into ThisWorkbook Module
    Any Subs having names starting with "Worksheet_..." go into the module for the worksheet you want then to work on.
    There are exceptions, but that's a pretty safe bet.
    Last edited by shg; 06-05-2010 at 03:22 PM. Reason: deleted spurious quote

  5. #5
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: UDF - Auto refresh issue

    Hi Foxguy,

    I get a compile error "Method or data member not found" when I run the macro after adding your code.

    I have attached a sample file.

    Many thanks
    Asha
    Attached Files Attached Files

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: UDF - Auto refresh issue

    If you want to calculate all the sheets in the workbook when any change is made on any sheet.

    Try this in the workbook module
    Please Login or Register  to view this content.

    This will calculate all open workbooks
    Please Login or Register  to view this content.

    Cheers
    Last edited by Marcol; 06-05-2010 at 01:30 PM.

  7. #7
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: UDF - Auto refresh issue

    Asha;

    I get a compile error "Method or data member not found" when I run the macro after adding your code.
    My mistake. I didn't test it first.
    The Line
    Please Login or Register  to view this content.
    Should be
    Please Login or Register  to view this content.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: UDF - Auto refresh issue

    Instead of making the UDF volatile, you could pass the range of interest. Then it would recalculate only when needed.

    Or, instead of recalculating all sheets on a change, you could calculate only the cell(s) in which the UDF appears.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Forum Contributor
    Join Date
    02-09-2010
    Location
    Constanta
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: UDF - Auto refresh issue

    Hi Marcol,
    Your code to calculate all sheets fixes the problem - many thanks.

    Hi Foxguy,
    Thanks for your response but the UDF still gives #VALUE! error after using the modified code you provided.

    Hi Shg,
    Though Marcol's code solves my problem, I would also like to understand & test the solution you have offered. Unfortunately, my VBA skills are poor. If possible could you please advise how to "pass the range of interest" or recalculate only the cells in which the UDF appears. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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