+ Reply to Thread
Results 1 to 2 of 2

Changing a cell reference on the fly within a formula referring to another workbook

  1. #1
    Registered User
    Join Date
    07-31-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    1

    Unhappy Changing a cell reference on the fly within a formula referring to another workbook

    Okay, so that isn't the best title, so here is my dilemma:

    I have the following formula in the current worksheet in cell K7, which brings in the row number for where the first instance of the date first occurs in the referenced file:

    =IF(MATCH(A$2,'[July 2013 IDX Cash Final Post.xlsm]Prep for Pivot'!$I$1:$I$20000,0),MATCH(DATE(YEAR($A$3),MONTH($A$3),VALUE(MID(CELL("filename",$A$1),FIND("]",CELL("filename",$A$1))+1,256))),'[July 2013 IDX Cash Final Post.xlsm]Prep for Pivot'!$D1:$D$20000,0),0)

    This particular formula results in 75. So I now know that the first instance is in cell D75 in the referenced file. But in the next cell down I want to know where the 2nd instance is, then in the next cell, the 3rd instance, etc. What I want to occur is for "$D$1" (toward the end of the formula) to update based on the result of the cell above. So I want the formula in the next cell below the cell containing the formula resulting in "75" to be:

    =SUM($K$7:$K7)+IF(MATCH(A$2,'[July 2013 IDX Cash Final Post.xlsm]Prep for Pivot'!$I$1:$I$20000,0),MATCH(DATE(YEAR($A$3),MONTH($A$3),VALUE(MID(CELL("filename",$A$1),FIND("]",CELL("filename",$A$1))+1,256))),'[July 2013 IDX Cash Final Post.xlsm]Prep for Pivot'!$D76:$D$20000,0),0)

    and yes, it has to be one row farther down than the previous result.

    I attempted to do this by first breaking the formula up into pieces, so that I could isolate and change the cell reference, and then put it back together again with CONCATENATE. Then I tried using INDIRECT to change the text string that resulted back into a formula. But I keep getting a #REF! error even though the other file I am referencing is open. So then I tried, doing the concatenation within the INDIRECT function, but it gets hung up on the double quotes throughout the string.

    Is there a simpler way to change the cell reference?
    Or, if not, how do I get the Indirect function to work?

    This has been driving me crazy!

  2. #2
    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,926

    Re: Changing a cell reference on the fly within a formula referring to another workbook

    Hi and welcome ot the forum

    with a complex formula like that, the best way (as you did) is to break it up into smaller bites...and maybe even keep those smaller bits in their own cell/helper column and then reference them to simplify the formula.

    Then, when I have a tricky INDIRECT() formula to concoct, I create it in te normal way (using the mouse etc) as if I was not going to use INDIRECT() - I then "text" the formula (remove the = or add '), so that I can see what it needs to look like - copy that down to another cell and then start adding in the indirect() a piece at a time until I get it where it needs to be.

    How to apply that to your formula? I couldnt say, without seeing what you are working with , but give the above a try and see how far you get?
    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] Link formula referring to other workbook keeps changing.
    By leaning in forum Excel General
    Replies: 14
    Last Post: 06-07-2013, 03:15 AM
  2. [SOLVED] Formula Updating - Changing Cell Reference
    By Nitsirk82 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-29-2012, 08:05 AM
  3. Changing cell reference in a formula when inserting a row
    By Apel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2009, 01:46 AM
  4. Replies: 4
    Last Post: 03-14-2005, 12:06 PM
  5. [SOLVED] A cell reference in a formula changing
    By knemitz in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-28-2005, 03: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