+ Reply to Thread
Results 1 to 11 of 11

Altering existing formula to work with closed workbooks?

  1. #1
    Forum Contributor
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2013
    Posts
    131

    Altering existing formula to work with closed workbooks?

    Howdy! I have a formula that's loading a list of names based on how many times it's repeated on another document. It works wonderfully!

    My only issue is, I found out after trying to show it to someone else that the workbook it's referencing needs to be open for it to return the correct values. I'm trying to figure out how to re-work the existing formula to still do what it's currently doing, but not be dependent on the source workbook being open. After 3 hours of trying to wrap my head around SUMPRODUCT and how to make that work with what I want to do, I figured I'd do what I always do when I"m ready to beat my head against my desk:

    Ask y'all for help :P

    Here's my formula currently:
    {=IF(ROWS(B$15:B15)>$O$15,"",INDEX(MainDoc.xlsx!ColumnName,SMALL(IF(MainDoc.xlsx!UserName=$H$1,ROW(MainDoc.xlsx!UserName)),ROWS(B$15:B15))))}

    I'm currently having to enter these as array formulas to make them work, and as mentioned the MainDoc.xlsx has to be open otherwise everything just says #VALUE!. Any ideas how I can achieve the same result?

    Any input would be wonderful! Thanks, this forum is always crazy helpful.

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

    Re: Altering existing formula to work with closed workbooks?

    If MainDoc.xlsx is a separate file that you are trying to access, then your syntax is incorrect - you should have the filename (plus extension) inside square brackets, followed by the sheet name on that file and preceded by the full path to that file, and all of that should be inside apostrophes before the !

    I assume that ColumnName and UserName are named ranges defined within that file.

    Also, as you are using a filename with an .xlsx extension, then you are clearly not using XL2003 anymore, as it states in your profile - please update this.

    Hope this helps.

    Pete

  3. #3
    Forum Contributor
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2013
    Posts
    131

    Re: Altering existing formula to work with closed workbooks?

    Such a simple error on my part. Thanks so much, that worked beautifully!

    And I updated my excel year, good catch, didn't realize I'd mistyped it

  4. #4
    Forum Contributor
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2013
    Posts
    131

    Re: Altering existing formula to work with closed workbooks?

    Looks like I spoke to soon. I closed the workbook and re-opened to see if the new changes worked, and all the cells are returning #VALUE! still. Here's the updated syntax:

    {=IF(ROWS(B$15:B15)>$O$15,"",INDEX('C:\test\[MainDoc.xlsx]Sheet1'!ColumnName,SMALL(IF('C:\test\[MainDoc.xlsx]Sheet1'!UserName=$H$1,ROW('C:\test\[MainDoc.xlsx]Sheet1'!UserName)),ROWS(B$15:B15))))}

    Is the IF statement causing it to not return values properly or? The #VALUE! errors all go away and return with the correct information once I open the MainDoc.xlsx sheet. I'm just trying to get it to return the data without that sheet having to be open.

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

    Re: Altering existing formula to work with closed workbooks?

    Glad to be able to help - thanks for the rep.

    If that takes care of your original question, please select Thread Tools from the menu above your first post and mark this thread as SOLVED.

    Pete

  6. #6
    Forum Contributor
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2013
    Posts
    131

    Re: Altering existing formula to work with closed workbooks?

    Heya! Sorry, your method looked to work, but then I closed the doc and re-opened fresh and it was still returning the #VALUE! error. Not sure if anything's wrong with the updated syntax I posted earlier or if I need to use a different function to retrieve the data from a separate file.

    If you have ideas, I'm all ears

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

    Re: Altering existing formula to work with closed workbooks?

    I've just been trying to search XL Help to see if there is some restriction on using array functions with closed workbooks, but since I upgraded to Windows 10 last week I've not been able to access Help. I think that might be the problem.

    I tend not to use that approach (of using INDEX/SMALL/IF... through an array formula) - instead, I like to use a helper column to identify records which match the criteria and then you can just use a standard (non-array) INDEX/MATCH formula with the ROWS function to increment through the identified records.

    Perhaps you can provide a mock-up sample workbook which has the same data layout as you use, with one sheet equivalent to the external file (makes it easier to test out) and the other sheet equivalent to your current file, and then I'll be able to trouble-shoot your formula more easily, and try out some alternatives.

    Pete

  8. #8
    Forum Contributor
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2013
    Posts
    131

    Re: Altering existing formula to work with closed workbooks?

    Sure thing! Attached is a mockup book. Sheet1 would represent the document pulling the info, and the other tab would be a completely different, unopened document.

    I copied/pasted my formulas but for some weird reason that I don't feel like digging into since it's a test sheet, the values it's returning are from the cell below where it's finding the info.

    Basically, I just need it to do what it's doing but pull from a closed sheet
    Attached Files Attached Files

  9. #9
    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
    53,049

    Re: Altering existing formula to work with closed workbooks?

    I think what Pete meant was something like this in your "closed" workbook...
    =IF(A2=Sheet1!$B$1,'This tab has to be a diff doc'!F1+1,'This tab has to be a diff doc'!F1)

    Then use this for the extract..,.
    =IFERROR(INDEX('This tab has to be a diff doc'!A2:A11,MATCH(ROWS($A$1:A1),'This tab has to be a diff doc'!$F$2:$F$11,0)),"")
    copied down and across

    Note that that formula for the closed WB will NOT update if you change the name after the closed WB was saved
    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

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

    Re: Altering existing formula to work with closed workbooks?

    Hi there,

    I've been out visiting, so sorry for the delay in responding. Thanks to Ford for stepping in.

    The attached file shows the approach I had in mind, which is a bit different than Ford's - I've put all the formulae in Sheet1, which is to be in the "Open" workbook, so that they get updated. I've also renamed the "This tab has to be a different doc" sheet to "Closed", as it is a bit easier to follow.

    I've inserted two new columns (A and B) in Sheet1, for use as helper columns (coloured blue), and consequently your table gets shifted over. I've also set up a data validation drop-down in D1 where you can choose from the names listed in column N, making use of the named range "Names" - I've not used your other named ranges, as it is easier to copy a formula across if it uses column references. I didn't need the value that you had in C1 (formerly A1), so I've deleted that. I put this formula in A4:

    =IF(Closed!$A2=$D$1,MAX(A$3:A3)+1,"-")

    and this one in B4:

    =IF(ROWS($1:1)>MAX(A:A),"-",MATCH(ROWS($1:1),A:A,0)-2)

    The first one (which I would normally have in the other sheet if we were only working on one file) identifies the record(s) which match the criteria by giving each a unique sequential number, and the second one identifies the row in the Closed sheet where those records occur, all bunched up. By returning hyphens for non-matched records, you can easily see where the formulae are active - these should be copied down beyond the amount of data that you have in the Closed sheet (I've copied to row 29), and then the columns can be hidden if you want the sheet to look like it did before.

    I then put this formula in C4:

    =IF(OR($B4="",$B4="-"),"",INDEX(Closed!B:B,$B4))

    which can then be copied across to F4. Note that the formula in column B means that we only have to calculate the MATCH function once for each record, rather than include it within an INDEX/MATCH in columns C to F. C4 and F4 need to be formatted as a date (the others are General), and then the formulae can be copied down as far as you think you need them.

    You can test this out quite easily by changing the name in D1 and seeing the data change appropriately.

    I'll now separate these out into two files, MainDoc.xlsx and Open.xlsx and put them into a C:/temp directory to test them out as independent files.

    Hope this helps.

    Pete
    Attached Files Attached Files

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

    Re: Altering existing formula to work with closed workbooks?

    Okay, after an infusion of coffee I can now give you the next phase.

    I've attached two files, ef838a_Open and ef838b_MainDoc, which you should save into the folder C:/temp with the same names. The ef838b_MainDoc file just comprises the Closed sheet with your table of data, and I have deleted your named ranges as I don't make use of them.

    If you open the ef838a_Open file you must enable the automatic update of links, and then you can see that the formulae have changed as follows:

    A4: =IF('C:\temp\[ef838b_MainDoc.xlsx]Closed'!$A2=$D$1,MAX(A$3:A3)+1,"-")

    B4: =IF(ROWS($1:1)>MAX(A:A),"-",MATCH(ROWS($1:1),A:A,0)-2) (i.e. no change, as it just refers to data within Sheet1 of the Open book)

    C4: =IF(OR($B4="",$B4="-"),"",INDEX('C:\temp\[ef838b_MainDoc.xlsx]Closed'!B:B,$B4))

    If you change the name in D1 you will see the data change automatically.

    As Ford pointed out before, you cannot just change the name of the ef838b_MainDoc file by renaming it - the way to do that is to open the file, then use File | Save As to save the file with a new name, and then the items in red above will also change. If you want to get data from your own version of the MainDoc file, then you can just remove the ef838b_ from the formulae in A4 and C4, and copy them down again (you may need to copy down further if you have more data than in your example file). I suspect also that you might have more columns in your real file, so you may need to copy the formula in C4 across further and apply appropriate formatting before copying those down.

    Hope this helps.

    Pete
    Attached Files Attached Files

+ 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] How do I get the following formula to work when referencing a closed workbook?
    By HumbleAko in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-26-2015, 05:46 PM
  2. [SOLVED] Altering existing formulas using VBA code
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-14-2014, 11:35 AM
  3. [SOLVED] Altering the existing macro to get date as numerical va;ue
    By ajang in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2013, 08:27 PM
  4. Replies: 15
    Last Post: 11-15-2011, 03:22 PM
  5. Altering existing macro code
    By jsmity in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-03-2010, 01:05 PM
  6. Replies: 0
    Last Post: 09-22-2009, 04:11 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