+ Reply to Thread
Results 1 to 20 of 20

How to avoid indirect volatile function

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    How to avoid indirect volatile function

    Hi,

    as i started to read about volatile functions i found out that my workbook is using too many indirect functions.
    So it can cause bad overall performance and i always want to have the fastest workbooks in the world :D

    I am pulling data out from Access from queries and i am clearing range, adding tables with specific names.
    And formulas using indirect are working like a charm.

    How can i replace indirect formula?
    I have a lot of source tables one by one, (one below another).

    I can not refer to table directly like "Table1" because when i will delete, and recreate dynamic table i will have error in formula (REF error).

    Please help how to change it properly?
    To mirror error try to delete source table, and add the same table with the same structure and name.
    Indirect will work, the direct formula not.

    Best,
    Jacek
    Attached Files Attached Files

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,705

    Re: How to avoid indirect volatile function

    If you changed the formula in C1 of Sheet1 to this:

    =VLOOKUP(A1,Sheet2!A:B,2,0)

    then when you delete the table and re-enter it the formula will still work.

    I suspect that your example is very simplified.

    Hope this helps.

    Pete

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    hi Pete_UK,

    it would be good but i can change source tables size and i am adding them one by one in the column.

    And if i change table name in a query or add new column i can not refer to it using your formula - so i will have to change all formulas.

    With indirect i do not have problem like that because i am refering to table header name - no matter where table is or it was moved or added new columns.

    Best,
    Jacek

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: How to avoid indirect volatile function

    My suggestion would be using VBA to clear the data from the table, connect to the database and import 'new' data and carry on as you were without the need for INDIRECT at all. But impossible to say if that would work for you without sight of the project in a form that's a little more comprehensive than the sample provided.

    EDIT: Having now read your subsequent post even the formulas could be updated via VBA so dynamic placement of columns would be accounted for.

    BSB

  5. #5
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    BadlySpelledBuoy you mean delete only table data not whole table and populate it?

    It would be good but if you add new column or move some columns or move table it can be a problem.

    Best,
    Jacek

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: How to avoid indirect volatile function

    Yes that's exactly what I mean. You can delete the body of the table but leave the table, including any formulas and formatting, in place then use SQL in the VBA to bring the refreshed data in.

    Quote Originally Posted by jaryszek View Post
    It would be good but if you add new column or move some columns or move table it can be a problem.
    See my edit to post #4.

    You could have VBA to reapply all the formulas and find specific columns based on header position so it wouldn't matter if you added new ones or moved existing ones.

    BSB

  7. #7
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    Hi BadlySpelledBuoy,

    thank you,

    in place then use SQL in the VBA to bring the refreshed data in.
    this is interesting, using adodb sql command?
    It will be select statement combined with databodyrange from table?
    What about headers? How to skip them?

    You could have VBA to reapply all the formulas and find specific columns based on header position
    what do you mean by this? Do you have any example?

    Jacek

  8. #8
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: How to avoid indirect volatile function

    Yes, ADODB SQL indeed. I do exactly that to pull data from Access into Excel all the time in my work. The reason is I found that pulling the results from a query built in Access into Excel through a connection often brought back incorrect data if the query was anything more than very straightforward but querying the database directly through SQL in the VBA produced the correct results.

    You can query the database and have all the results in a record set which you can then stamp into a table, including headers, and the table will adjust to account for any additional fields/columns youv'e added. Of course that will throw your formulas out but as mentioned, there's possibility to simply overwrite all the formulas using VBA so everything will be realigned by the time it's finished refreshing.

    That approach will very much depend on the complexity of your actual workbook. If there are thousands of different formulas then you may not want to update them all each time, but there is the possibility of changing the formulas in the first instance to calculate from "named ranges" rather than table fields or range references. Then when you import the data you could use VBA to simply update all the named ranges and in theory everything will be fine. I say in theory because without seeing the actual workbook it's difficult to say for sure....

    BSB

  9. #9
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    Hi,

    Please Login or Register  to view this content.
    i have a lot of queries which i am pulling out from Access to Excel using "select * from qry_Name" and this is working.
    What exact query are not working?

    Yes, i can add named ranges with reference to dynamic tables. But i would have use indirect function there.
    It is also volatile funcion even it is used in named range?

    Please Login or Register  to view this content.
    Using this code i have a lot of queries dynamic tables in Excel one by one.

    I can not see possibility to replace indirect for address formulas in this case.

    Best,
    Jacek
    Last edited by jaryszek; 12-28-2018 at 03:13 AM.

  10. #10
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    In attachment please find how my source worksheet (Sheet2) is looking.

    Issue with keeping tables (not deleting them) is that they can be bigger as new records will added.
    So they will change their addresses.

    Best,
    Jacek
    Attached Files Attached Files

  11. #11
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: How to avoid indirect volatile function

    Perhaps a different layout is required then. Additional sheets with one table per sheet? At least that way they will always start at the same point... But I can see why this would not be desirable.

    I still don't see the problem with deleting only the DataBodyRange of the tables leaving the structure intact, refreshing the data and if any new columns have been added using VBA to redefine the named ranges' addresses. That way your formulas wouldn't end up showing #REF! and you don't have to reapply potentially thousands of formulas. Doing this would negate the need to use INDIRECT at all because your table names would remain constant.

    OR, if you add a new field to the database/query then also add it to the Excel table before you refresh it so that everything can auto adjust prior to new data.

    OR, if you're not the one adding the fields to the database then have the VBA check if the headers match prior to bringing in new data, adjust columns by adding new ones where necessary and then refreshing the data.

    There are many ways around this problem, but we have so little information on actual structure that it's impossible to give definitive solutions.

    BSB

  12. #12
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    i have to rethink whole idea.
    Thank you.

    I do not like the idea to keep tables, this can cause a lot of issues.

    Now after few seconds i have all queries downloaded into Workbook.
    And even users will add 100 hundred new records - it is not harmful for me.

    Best,
    Jacek

  13. #13
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: How to avoid indirect volatile function

    Quote Originally Posted by jaryszek View Post
    I do not like the idea to keep tables, this can cause a lot of issues.
    I'm not sure what issues you mean, but perhaps the questions should be, will it cause MORE issues than use of INDIRECT is already causing??

    BSB

  14. #14
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    BSB,

    yes your question hit the jackpot ;-)

    Jacek

  15. #15
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: How to avoid indirect volatile function

    If the number of columns per table is unlikely to change (and I can't see why it would without you needing to rebuild what you're doing anyway), I'd suggest putting your tables adjacent to each other (if you really can't have them on separate sheets, which would be my preference for reference tables), linking them to the data source and then just refreshing them. No need for INDIRECT, or code, unless you need to change the query.
    Rory

  16. #16
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    O wow, it is good thinking, thank you!

    Now i am establishing connection with Access and retreving all tables.
    What code should i use to only refresh previously downloaded tables?

    Can you help with that?

    Best,
    Jacek

  17. #17
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: How to avoid indirect volatile function

    What exactly do you mean by "previously downloaded". Surely all existing connected tables have been downloaded previously?

  18. #18
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    Yes,
    Surely all existing connected tables have been downloaded previously?
    aa ok in my code i am unlinking all tables:

    Please Login or Register  to view this content.
    So if i will not unlink them i should have possibility to refresh them?

    And how this linking connections is working? Only inside table queries or has impact also on workbook performance like power query?

    Jacek

  19. #19
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: How to avoid indirect volatile function

    A Table is a Table. Once refreshed, it shouldn't matter whether it's linked to external data or not. I'm not sure what your comment about PQ refers to.

  20. #20
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: How to avoid indirect volatile function

    When you are opening Excel with PQ framenet is loading and is taking a few more seconds = worse performance.

    Ok i have to try your approach.
    Thank you!

    Best wishes,
    Jacek

+ 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. Is INDIRECT function volatile within an IF function?
    By Monimonika in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-29-2017, 12:53 PM
  2. Non-volatile substitute for INDIRECT function
    By AndyFarrell79 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-24-2014, 03:29 AM
  3. Non-volatile alternative to INDIRECT
    By elliotencore in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-21-2013, 11:28 AM
  4. INDIRECT function within VLOOKUP to avoid #REF error???
    By Hozcat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2012, 10:30 AM
  5. Volatile INDIRECT
    By wjsok85 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-23-2010, 07:53 AM
  6. Replacement for using Indirect (Volatile)
    By jeffreybrown in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-31-2009, 09:54 AM
  7. How to avoid volatile hyperlinks?
    By count in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2006, 12:06 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