+ Reply to Thread
Results 1 to 4 of 4

counting criteria in closed workbook

  1. #1
    Registered User
    Join Date
    07-13-2023
    Location
    Australia
    MS-Off Ver
    365
    Posts
    10

    counting criteria in closed workbook

    hello, I have a workbook in which I need to pull in data from several closed workbooks. INDIRECT and COUNTIFS don't work with closed workbooks as far as I can ascertain.

    I've had success with SUMPRODUCT while the path, file, tab, range are all hard coded into the formula.
    This all falls apart when I try to bring in variables.

    The workbooks to be interrogated all have the same file name, sheet names, headings etc. They only differ by the folder they are located in. The folder names I need to reference are listed in range of cells in my active workbook.

    I need to bring a COUNT of matching criteria from these workbooks based on values in several columns.
    As outlined, when I hard code the formula, all is well, but get errors (#REF), zero or the text of the formula I'm trying to create... I'll give example:

    - path, always the same, "\\server\common folder\path"
    - folder, variable (based on range of cells), "2024 R"
    - sheet, always the same, "data"
    - first critera range, will refer to whole column (no range names, no tables), "$M;$M" (="Active")
    - second criteria range, will refer to whole column (no range names, no tables), "$C;$C" (=$A$1 on the active sheet)

    works perfectly:
    =SUMPRODUCT(('\\server\common folder\path\2024 R\[financial result.xlsx]data'!$M:$M="Active")*('\\server\common folder\path\2024 R\[financial result.xlsx]data'!$C:$C=$A$1))

    when I try anything to incorporate the variable "2024 R" into the formula I get a differing errors (depending on what I'm trying).

    I would really appreciate any help with this.

    I am open to VBA or PowerQuery if that is a better option... (but would still require how to do this)

    Thank you
    Last edited by dave_63; 03-18-2024 at 12:49 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: counting criteria in closed workbook

    How are you adding the variable to the formula? Are you simply trying to add a cell reference?

    Try this:

    =SUMPRODUCT(INDIRECT("('\\server\common folder\path"&variable&"\[financial result.xlsx]data'!$M:$M="Active")")*IDIRECT("('\\server\common folder\path"&variable&"\[financial result.xlsx]data'!$C:$C=$A$1)"))

    where variable is a cell reference.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    07-13-2023
    Location
    Australia
    MS-Off Ver
    365
    Posts
    10

    Re: counting criteria in closed workbook

    Thanks for your assistance Ali. Yes I am trying to do this via cell reference as you've described in your formula. Unfortunately I still get the #REF! error message. Incidentally, the second occurrence of the indirect formula still shows as part of 'array 1' in the SUMPRODUCT formula; I would expect to be 'array 2' (I don't know if that's significant).

    kind regards
    Dave

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: counting criteria in closed workbook

    It would be easier if you shared two small sample workbooks for testing.

    There was a typo in my formula. Try again:

    =SUMPRODUCT(INDIRECT("('\\server\common folder\path"&cellreference&"\[financial result.xlsx]data'!$M:$M="Active")")*INDIRECT("('\\server\common folder\path"&cellreference&"2024 R\[financial result.xlsx]data'!$C:$C=$A$1)"))

    If not, then provide the samples I mentioned.
    Last edited by AliGW; 03-19-2024 at 02:08 AM.

+ 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. Get data from a closed workbook with criteria using ACE.OLEDB SQL
    By zr3cool in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-28-2019, 06:59 AM
  2. Export data with two Criteria values from closed workbook to closed workbooks VBA
    By julielara in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2016, 01:56 PM
  3. Count with multiple criteria from a closed workbook
    By rcharity23 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-27-2014, 02:33 PM
  4. Transfer Data from one workbook to worksheets in a closed workbook by criteria
    By jftapel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-21-2012, 05:23 AM
  5. GetValues from a Closed Workbook with a conditions/criteria
    By cmarenco in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2012, 05:37 PM
  6. Counting blank cells in a closed workbook
    By Roan242 in forum Excel General
    Replies: 1
    Last Post: 04-29-2010, 11:05 AM
  7. Add closed workbook filenames that meet certain criteria to a message box
    By rdblatch in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-21-2005, 05:00 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