+ Reply to Thread
Results 1 to 10 of 10

Replace INDIRECT with more elegant function

  1. #1
    Registered User
    Join Date
    09-08-2010
    Location
    Montenegro
    MS-Off Ver
    Excel 2010
    Posts
    82

    Replace INDIRECT with more elegant function

    Hi. I'd appreciate if someone can shed some light if there is a way to replace INDIRECT in this example below.

    I have a "source workbook" of raw data, with about 20 sheets, each one containing about 10-30 columns and several thousands rows. Columns captions (always in row 1) are standardized, but they are not ordered in the same order in all sheets, and not all the sheets contain all the columns. This is example of sheet "src1" in source workbook:

    \1

    I have another, "my workbook", to process these data. I want to extract data from one sheet of "source workbook" at a time, so I specify the desired sheet in "my workbook", cell A2 in this example. It looks up for the data by caption and, in this example, by Order ID, which is specified in column C of "my workbook".

    \1

    Formula in D2 is:

    =IFERROR(INDEX(INDIRECT("[source.xlsx]"&$A$2&"!$A$1:$G$160"),MATCH($C2,INDIRECT("source.xlsx]"&$A$2&"!$A$1:$a$160"),0),MATCH(D$1,INDIRECT("[source.xlsx]"&$A$2&"!$A$1:$G$1"),0)),"n/a")

    This formula looks up for Order # in sheet "src1" of source workbook (specified here in cell A2), and returns value from appropriate column; if there is no such a column on that sheet ("Approval time" in this example), it returns "n/a". So it works fine, but I kind of don't like this part

    INDIRECT("[source.xlsx]"&$A$2&"!$A$1:$G$160")

    and other two occurences of this function.

    Is there a way to replace it with some other, simplier and possibly faster function, to reference sheet in "source workbook" specified in cell A2 of "my workbook", second screenshot above? It works acceptably fast, say about 1 second to process all the data when I change sheet or some other input, on a new computer, but at my older laptop at home, it takes as much as 7-8 seconds, and I guess it might be because of INDIRECT.

  2. #2
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Replace INDIRECT with more elegant function

    It is more likely that your laptop is running on an older version of Excel, older OS or lower Ram. It is also likely that one system is in a 64 bit environment and the other is in 32 bit (this matters only when trying to use more RAM as 32 Bit OFFICE will utilize less RAM where the 64 BIT will allow you to access virtually all your RAM). So I would say compare the specs as the indirect function matched with an index/match is a solid solution that is recommended when pulling from other workbooks and/or multiple sheets. You can take the time to write the exact lookup instead but then you lose flexibility and I would not venture that way.

    I think you will find that in comparing the specs of the office pc to your laptop you will find that one has higher RAM, better processor and likely a different environment all together. Note that just because you are in a 64 bit Windows environment does not mean your OFFICE is also 64 bit, you can run (A lot of people have it setup to) run 32bit OFFICE on a 64bit windows environment.

    But directly to your question, I do not believe there is a better solution for what you are doing with that many books, sheets and records! (But I am not all knowing so perhaps someone else will have a trick up their sleeve)

    Cheers -
    -If you think you are done, Start over - ELeGault

  3. #3
    Registered User
    Join Date
    09-08-2010
    Location
    Montenegro
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Replace INDIRECT with more elegant function

    Thank you for prompt reply!

    Both machines are 64 bit with 4 GB RAM, but at home is Excel 2007, and 2010 at work. Cannot bother now to look for further specifications, as that cannot be changed at the moment, so if there is no better formula, I'll have to settle for that solution.

    I agree that "hard-coding" sheets name or column captions into "my workbook" would rob me of flexibility, that's why this solution is still better.

  4. #4
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Replace INDIRECT with more elegant function

    There is some Ram issues I know I ran into with 2007 when utilizing more than 7 sheets.
    Check your office version though - Go to File>Account> About Excel or it may be in the Help toolbar.

    But like you said if that is the latency source there is not much you can do about it now -

    Cheers

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Replace INDIRECT with more elegant function

    Just for clarification on the RAM limitations, it doesn't matter if your machine is 32 or 64 bit as much as what the installation of Office is. The default installation on both 32 and 64 Windows is 32 bit Office. You have to take a few extra steps at the beginning of the installation process to install it as 64 bit Office on a 64 bit Windows machine. The RAM issue only comes into play in very large workbooks.

    As for the delay, you can test RAM speed, etc. but in general speed is a relative issue and there are many, many reasons why this could be happening. I highly doubt this is being cause by Excel not being able to access more than 2 GB of RAM.

    My alternative to your problem is try to set up an intermediate cell where the Indirect formula would be and reference that cell. You are currently calculating the Indirect formula three times, but if you used an intermediate cell then it should cut the speed down a bit. It might not be noticeable, but worth a try.

    Good luck.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  6. #6
    Registered User
    Join Date
    09-08-2010
    Location
    Montenegro
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Replace INDIRECT with more elegant function

    Thanks for further info, guys! This goes out of scope, as I have no intention of changing the machine or reinstalling the Office at the moment; I thought there would be an alternative to INDIRECT, but if there's not, it'll have to run this way.

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Replace INDIRECT with more elegant function

    The indirect function will slow down the performance.

    But why not all the data in 1 sheet (instead of 2 files)?
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  8. #8
    Registered User
    Join Date
    09-08-2010
    Location
    Montenegro
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Replace INDIRECT with more elegant function

    Quote Originally Posted by oeldere View Post
    But why not all the data in 1 sheet (instead of 2 files)?
    Source file that contains raw data is external file, I receive it from external source, and it gets updated weekly. So if I wanted to have them all in one workbook, I would have to either copy/paste formulas within each sheet of source file every week (and there are some 20 sheets inside), either to check for new data in updated raw file and copy/paste them in my workbook. It's easier and error-proof if I just replace the old raw file with new one, and extract the data using formulas.

  9. #9
    Registered User
    Join Date
    08-06-2020
    Location
    US
    MS-Off Ver
    365
    Posts
    1

    Re: Replace INDIRECT with more elegant function

    I know it's been 5 years, but I stumbled across this when I was searching for an alternative.
    If anyone else is in need of a solution, this UDF (found on another forum) helped me.

    Public Function IndirectNotVolatile(sheetName As String, sheetRange As Range) As Variant
    Set IndirectNotVolatile = Worksheets(sheetName).Range(sheetRange.Address)
    End Function
    Last edited by jbiehl; 10-25-2020 at 09:41 PM.

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Replace INDIRECT with more elegant function

    Quote Originally Posted by jbiehl View Post
    I know it's been 5 years, but I stumbled across this when I was searching for an alternative.
    If anyone else is in need of a solution, this UDF (found on another forum) helped me.

    Public Function IndirectNotVolatile(sheetName As String, sheetRange As Range) As Variant
    Set IndirectNotVolatile = Worksheets(sheetName).Range(sheetRange.Address)
    End Function
    Thanks for the input, Im sure others will find this helpful.

    For those that use thos suggestion, keep in mind that a UDF (User Defined Function) is really a macro, and your file will need to be saved in .xlsm format
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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] INDIRECT Function with multiple sheets - SUMIF, INDIRECT & MATCH
    By DJDRU in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-07-2014, 08:42 AM
  2. [SOLVED] Is there a shorter, more elegant way of writing this? [long function]
    By johanna0507 in forum Excel General
    Replies: 2
    Last Post: 11-01-2013, 11:07 AM
  3. Trying to replace INDIRECT with INDEX or another function
    By deadlyduck in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-05-2009, 12:51 PM
  4. More Elegant solution to function submitting
    By Mat_Davies in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-16-2009, 09:06 AM

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