+ Reply to Thread
Results 1 to 16 of 16

Index Array Match - 1004 Error

  1. #1
    Registered User
    Join Date
    06-16-2015
    Location
    The Netherlands
    MS-Off Ver
    2016
    Posts
    52

    Lightbulb Index Array Match - 1004 Error

    Dear all,

    I have nearly solved my puzzle and need one final piece to be solved. I have been playing and searching around for days, but withouth any luck. Hopefully one of you can help me.

    I use the working formula below to get the first result for an Index formula:
    =INDEX('[151109 TM05 - HR Planning (Total).xls]Succession Plans'!$E$2:$E$20000;SMALL(IF($A2='[151109 TM05 - HR Planning (Total).xls]Succession Plans'!$N$2:$N$20000;ROW('[151109 TM05 - HR Planning (Total).xls]Succession Plans'!$N$2:$N$20000)-ROW('[151109 TM05 - HR Planning (Total).xls]Succession Plans'!$N$2)+1);1))

    When I use the formula in a macro, I try the following:

    Range("BG2").Select

    Selection.FormulaArray = _
    "=INDEX('[" & cFileNametmb05 & "]SP'!$E$2:$E$20000,SMALL(IF($A2='[" & cFileNametmb05 & "]SP'!$N$2:$N$20000,ROW('[" & cFileNametmb05 & "]SP'!$N$2:$N$20000)-ROW('[" & cFileNametmb05 & "]SP'!$N$2)+1),1))"
    Selection.AutoFill Destination:=Range("BG2:BG150000"), Type:=xlFillDefault

    cFileNametmb05 is already declared earlier in the macro and works perfectly for other formulas. It thus, opens the cFileNametmb05 report (151109 TM05 - HR Planning (Total).xls), goes back to the target file, then selects cell BG2 and then gives me the famous 1004 error ("Unable to set the FormulaArray property of the Range class").

    I honestly hope that one of you smart people can help me out Any help is appreciated

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Index Array Match - 1004 Error

    What's the declaration type for the File Name?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    06-16-2015
    Location
    The Netherlands
    MS-Off Ver
    2016
    Posts
    52

    Re: Index Array Match - 1004 Error

    Sorry, should have given you the full macro . See below!

    Please Login or Register  to view this content.
    Last edited by Nipius; 01-06-2016 at 08:56 AM.

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Index Array Match - 1004 Error

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  5. #5
    Registered User
    Join Date
    06-16-2015
    Location
    The Netherlands
    MS-Off Ver
    2016
    Posts
    52

    Re: Index Array Match - 1004 Error

    Quote Originally Posted by JapanDave View Post
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Apologies! I have updated my post

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Index Array Match - 1004 Error

    Hi,

    Change the references in the formula from

    cFileNametmb05

    to

    cFileNametm05

    Incidentally although the variables are being declared by default, it's always preferable to explicitly declare the type and configure the VBE to always require variable declaration with an Option Explicit instruction above the code. Then use code like.

    Dim cFileNametm05 As String

    It's too easy to mistype a variable name and without an explicit declaration the mistyped name will automatically become a valid variable.

  7. #7
    Registered User
    Join Date
    06-16-2015
    Location
    The Netherlands
    MS-Off Ver
    2016
    Posts
    52

    Re: Index Array Match - 1004 Error

    Thanks, Richard. Understand what you mean!

    So, if I read your suggestion properly, I should change the code to the following:
    Please Login or Register  to view this content.
    I have made the adjustments, but still get the same error though

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Index Array Match - 1004 Error

    What do you see if you step through the macro and then hover over the cfilenametm05 variable when you hit the error message?

    Upload the workbook so that we may see the problem in context.

  9. #9
    Registered User
    Join Date
    06-16-2015
    Location
    The Netherlands
    MS-Off Ver
    2016
    Posts
    52

    Re: Index Array Match - 1004 Error

    Quote Originally Posted by Richard Buttrey View Post
    What do you see if you step through the macro and then hover over the cfilenametm05 variable when you hit the error message?

    Upload the workbook so that we may see the problem in context.
    I see the name as it should be.

    Attached the files I use. Due to the confidentiallity, I have only kept the employee ID's. Also, I have disabled some parts of the code in the macro, as I know they work, but not now as I have also deleted some tabs (also due to confidentiality).

    There are 3 files attached. Please open the TR2 - Test (Forum) file. On the sheet "Start", update the paths for Integrated Report and TM05 (IA Tracker is not needed now). Then press update.
    As you can see, it updates all, but stops as soon as I get to the array formula.

    Hopefully this clarifies the issue
    Attached Files Attached Files

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Index Array Match - 1004 Error

    Hi,

    Why are you using the .FormulaArray instruction when the formula seems to be a straightforward simple indexing formula? Try a plain

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    On a more general point, and I admit I don't understand the minute detail of what you're doing but I question the necessity for all the looping code which is never very efficient. If you're grabbing data from another workbook, which seems the essence of the task, then a simple Data Advanced Filter would seem the obvious way to go and perform the task in a fraction of a second .

    Neither does all the .Select stuff help matters. This is rarely necessary and certainly not the case here. Just address the object directly rather than selecting it.

  11. #11
    Registered User
    Join Date
    06-16-2015
    Location
    The Netherlands
    MS-Off Ver
    2016
    Posts
    52
    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    Why are you using the .FormulaArray instruction when the formula seems to be a straightforward simple indexing formula? Try a plain

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    On a more general point, and I admit I don't understand the minute detail of what you're doing but I question the necessity for all the looping code which is never very efficient. If you're grabbing data from another workbook, which seems the essence of the task, then a simple Data Advanced Filter would seem the obvious way to go and perform the task in a fraction of a second .

    Neither does all the .Select stuff help matters. This is rarely necessary and certainly not the case here. Just address the object directly rather than selecting it.
    Thanks, Richard. Regarding your comments on my code. I wil def. have a look at the suggestions you gave! Although I most of the time know how to get the needed results, I consider myself still a starter when it comes to clean and efficient code.

    I do need to use an array code though. Let me elaborate on my need. The TR2 files combines data from several sources. It also shows the employee ID's (columns AC, AF, et cetera) for the employees marked as possible successor. Because the source (TM05) uses merged cells in sheet "Succession Plans" (f.e. E5) I unmerge the cells and give all empty cells in column E unique values.

    This all works fine in my current code. However, I would also like to see for which roles the talent itself is marked as a possible successor (column N in sheet "Succession Plans"). In contrary to the other exercise, here a name can show up several times. Employee X can be marked as a possible successor in column N for multiple employees in column E.

    Thus, if employee X is marked as a possible successor for employee A and B, I want to have the employee ID of employee A in column E (in sheet "Succession Plans") shown in column BG in sheet "Employees". The ID of employee B shoot be shown in column AR.

    I hope you understand what I mean

  12. #12
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Index Array Match - 1004 Error

    Sorry but it's not clear to me exactly what you want.

    Are you able to manually add a set of results that you want to see and add some notes explaining how you produced them. We can then work out the most optimum way of getting those results.

    I still don't see why you need an array formula when you're using an Index function to return a single value. Is there a misunderstanding on the term an 'array formula'
    i.e. with your formula

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    in a cell then no doubt it evaluates correctly.
    But what happens if you convert it to an ARRAY formula by entering it with Ctrl-Shift-Enter so that Excel adds the {} parentheses around it. Does it return an error?

  13. #13
    Registered User
    Join Date
    06-16-2015
    Location
    The Netherlands
    MS-Off Ver
    2016
    Posts
    52

    Re: Index Array Match - 1004 Error

    Thanks for your patience, Richard.

    Attached the target file with the results as I would like them (I have hidden all the columns that are not relevant for this issue).
    In the example, there are 3 employees. Both Charles Brown and Paris Hilton have possible successors for their roles. Charles has two (BB King and Sean Connery). Paris has one (Michael Jackson). For Jamie Fox there are no possible successors marked.
    Starting as of column BG (59), I would like to see for which role(s) the employees marked in column A are possible successors themselves. So, for example Paris Hilton. She has Michael Jackson as possible successor. But she herself is marked as a possible successor to Nicole Kidman and Penelope Cruz.

    In real life, there are quite some employees marked as a possible successor for 2 or more roles.

    Thus, when I look at the source file (TM05), for example employee ID 000000999 shows up more than once in column M (14). Meaning this employee is marked as a possible successor for several roles (the role from employees 000026343, 000043547, 000049291, 000046758). In the attached target file, I have added this employee ID and the role he is a possible successor for as well.

    So, the easy Index formula (without an array) is fine for me in order to define the possible successors for an employee. But the otherway around, I would expect to need an Array formula.

    I hope this clarifies my needs
    Attached Files Attached Files

  14. #14
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Index Array Match - 1004 Error

    Hi,

    I'm not entirely sure I still understand the precise requirement.

    You've listed 000026343 in R10:C59 of the TR2 report and in R10:C1 000000999 which happens to be the first ID in R5:C14 of the HR Planning Report which happens to be grouped with others covered by 000026343 in R5:C5.

    Is this the link and in the real world would you be adding the other 12 IDs covered by 000026343 in Rows 11:22 Column 1 of the TR2 sheet.

    One thing that does concern me is the merged cells in the HR sheet. These play havoc with any serious analysis and most of us avoid them like the plague since they just cause too many problems and make life more complicated than necessary. I don't know how the HR report is produced but I'm guessing it comes from some other back office system and it may be worth considering whether this could provide a more regular, and for Excel usable' layout of data.

    The overall requirement seems to revolve around either many to one matches or one to many matches to produce the successor type analysis that I think you're driving at. However without seeing a detailed spec. of the overall requirement I am still struggling. Something tells me that with different layouts this exercise might be simplified somewhat.

  15. #15
    Registered User
    Join Date
    06-16-2015
    Location
    The Netherlands
    MS-Off Ver
    2016
    Posts
    52

    Re: Index Array Match - 1004 Error

    Hi,

    I'm not entirely sure I still understand the precise requirement.

    You've listed 000026343 in R10:C59 of the TR2 report and in R10:C1 000000999 which happens to be the first ID in R5:C14 of the HR Planning Report which happens to be grouped with others covered by 000026343 in R5:C5.
    Correct. So employee 000000999 is one of 13 employees who possibly follow-up employee 000026343.

    Is this the link and in the real world would you be adding the other 12 IDs covered by 000026343 in Rows 11:22 Column 1 of the TR2 sheet.
    In the real world these other 12 ID's will show up anyways in column 1 of the TR2 Sheet. In the actual file all employee ID's for all employees in the company will show up in column 1 of the TR2 sheet. Thus, employee 000041600 (R6:C14 of the HR Planning Report) will be somewhere in column 1 of the TR2 sheet (not necessarily row R11:C1).

    One thing that does concern me is the merged cells in the HR sheet. These play havoc with any serious analysis and most of us avoid them like the plague since they just cause too many problems and make life more complicated than necessary. I don't know how the HR report is produced but I'm guessing it comes from some other back office system and it may be worth considering whether this could provide a more regular, and for Excel usable' layout of data.
    I could not agree with you more on the merged cells . However, as you mentioned correctly, this is produced by another system and is what it is. I use a work-around via a macro by first unmerging all cells in the HR Planning Report. This causes R5:C5 to keep the original value 000026343. The other cells then turn empty and get a unique value by adding an A. See attached file.
    In column 29 of the TR2 file, I use real employee ID's. In column 32, I use the concatenation of the Employee+A. In column 35, that concatenation +A (which results into Employee ID+AA).

    The overall requirement seems to revolve around either many to one matches or one to many matches to produce the successor type analysis that I think you're driving at. However without seeing a detailed spec. of the overall requirement I am still struggling. Something tells me that with different layouts this exercise might be simplified somewhat.
    You are right. As you can see in the updated attached file, each cell in column 5 has a unique value (no value returns twice). This way I can easily identify all possible successors for all employees mentioned in column 1 in the TR2 file. On the other hand, in column 14 of the HR Planning file, a lot of values show up twice or more.

    In the particular example of 000000999, R10:C59 in the TR2 file should show 000026343 (Index/Match in the HRPlanning file between R15:C14 and R5:C5:. R10:C70 (in TR2 file) should show 000043547A (Index/Match between R800:C14 and R800:C5 (in the HR Planning File)).

    When this is realized, I just deleted the A's in columns 61, 70, et cetera.

    I think we are getting there slowly, but steady. But I am more than happy to explain it even better if needed! Once again, thanks a ton for all your effort so far!
    Attached Files Attached Files
    Last edited by Nipius; 01-07-2016 at 03:43 AM.

  16. #16
    Registered User
    Join Date
    06-16-2015
    Location
    The Netherlands
    MS-Off Ver
    2016
    Posts
    52

    Re: Index Array Match - 1004 Error

    So.. I have been thinking about all the different reasons for the formula not to work.
    I changed the formula to refer to an array within the same Workbook (so not trying to get the information from an external Workbook). When doing so, it does work!

    I think I might go for the "ugly route" and copy paste the needed information into the target file before running the arrayformula.

+ 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] Match-Index in stead of Index-Match lookup Array among Arrays
    By Numnum in forum Excel General
    Replies: 2
    Last Post: 10-15-2015, 02:08 PM
  2. [SOLVED] Run Time Error 1004 within Array
    By Kramxel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2015, 04:11 AM
  3. VBA Index/match Error 1004
    By albertli in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2015, 09:37 PM
  4. Replies: 6
    Last Post: 04-30-2014, 02:42 AM
  5. index function error using match function to get data from a cell in an array
    By mabildgaard in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-17-2013, 02:21 AM
  6. [SOLVED] Match & Index code results in Runtime error 1004
    By DJvdW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2013, 03:52 AM
  7. Replies: 3
    Last Post: 05-02-2013, 01:31 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