+ Reply to Thread
Results 1 to 6 of 6

Too long array formula to insert with VBA

  1. #1
    Registered User
    Join Date
    06-21-2018
    Location
    Denmark
    MS-Off Ver
    Excel 2016
    Posts
    4

    Question Too long array formula to insert with VBA

    Hello!

    I'm having trouble inserting an array formula with VBA as it returns the 1004 error ("Unable to set the FormulaArray property of the Range class"). I've found out this is due to the string being too long (max 255 chars). Searching the net and forums, the general suggestion is to use a replace function to split it up and in general clear up the formula. However, when I do this myself, I still experience the same error message, even though I've broken my formula up into three distinct parts, each less than 255 chars.

    The idea is that we have a spreadsheet containing the basic data about a number of research proposals, one proposal per row. The spreadsheet consists of a number of data sheets, e.g. one containing the proposal details themselves, one containing assessment details, one containing details about the people and institutions involved in each proposal, etc. These are all combined in different ways in one central viewing sheet which is the only part seen by the end user. For each funding scheme, we might have a number of assessment criteria. So in this particular scheme, we have two peer reviewers assessing each application and each assigning three different scores. The scores themselves are stored in the data sheet containing assessments. Now, these sheets are often very large and slow when they pull them from Sharepoint, so instead of working with an active sheet which is always updated with the newest data, they copy and paste everything as values as the first thing they do when they get the sheet. Then they work from that.

    However, as the assessments come after the proposals themselves have been received, we need to be able to update the data source (easy enough) and re-insert the active formulas so that the scorings are fetched for each proposal - and also make sure it's the newest assessment in case of resubmission of the assessment. Now, my colleagues could conceivably have a list of formulas to use and just paste them in as needed. However, I just want them to have a button which inserts the formula with them having to do nothing else.

    Imagine therefore two tables with the following columns (descriptions in parentheses)

    Table 1: Viewing table: Sagsnr (case no.), applicant, title, etc, Scientific Quality
    Table 2: Data table (called "Bedømmelser"): Sagsnr (case no.), Type (assessor role), Parameter (kode) (which type of assessment to fetch), Indsendelsestidspunkt (time of submission)


    Below is a minimal (non) working example containing the code:

    Please Login or Register  to view this content.
    As you will see, in order to have a formula/function that is somewhat versatile, I've replaced some of the values with variables.

    How can I split this up in several parts that it might work?

    NOW, here's the tricky bit. If I had organisational control, I could have made another non-array formula. However, this entire solution is delivered by another bureau in the agency, and they won't support us and our spreadsheets unless we use the formulas provided by them. Therefore it is not a solution to use either helper columns or make another formula.

    How would you do it?

    Best regards,
    Kasper

  2. #2
    Registered User
    Join Date
    06-21-2018
    Location
    Denmark
    MS-Off Ver
    Excel 2016
    Posts
    4

    Re: Too long array formula to insert with VBA

    I have uploaded a workbook with some test data, a non-array version of the formula that inserts, and the array version which results in a run time error: ufile.io/xc4pn

  3. #3
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Too long array formula to insert with VBA

    Use replace

    Please Login or Register  to view this content.
    obviously
    edit Range() to be your range
    C to be your first sub section of the formula (maybe you have to extend it to include the commas and brackets to ensure it is unique)
    D to be your other sub section of the formula (maybe you have to extend it to include the commas and brackets to ensure it is unique)

    you can of course do this lots of times if conceptually your finding it hard to chop up the formula.
    Last edited by scottiex; 06-21-2018 at 07:26 PM.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  4. #4
    Registered User
    Join Date
    06-21-2018
    Location
    Denmark
    MS-Off Ver
    Excel 2016
    Posts
    4

    Re: Too long array formula to insert with VBA

    I may be a bit dimwitted As I said in my OP, I had already tried the replace trick, but to no avail since it gives me the same error 1004. So obviously I must be doing something wrong:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Too long array formula to insert with VBA

    Each part needs to make sense e.g be able to be entered into a l if you were to do it manually as that is what you will effectively be doing.

    Ie formulapart1 is a valid formula in itself
    and it is also valid with formulapart2 substituted into it.

    To keep it conceptually easy - in your formula there seems to be a lot of this sort of thing -

    Please Login or Register  to view this content.
    which you could easily put in formulapart2 (or 3,4,5) and replace with something like "C1" or anything else that would be valid in that space in formulapart1 (and unique so it doesn't accidentally replace other parts of the formula)
    Last edited by scottiex; 06-23-2018 at 04:20 PM.

  6. #6
    Registered User
    Join Date
    06-21-2018
    Location
    Denmark
    MS-Off Ver
    Excel 2016
    Posts
    4

    Re: Too long array formula to insert with VBA

    Cheers, that did the trick, making it syntactically valid. Which sort of makes sense, now that I think about it. Thanks!

    For the interested: I'd post the adjusted code, but apparently I don't have the seniority to post it here yet But on pastebin.com/tvU7DezT you can find it.
    Last edited by KSimonsen87; 06-24-2018 at 03:17 PM.

+ 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] Code for long array formula
    By chuttus in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-14-2018, 04:06 PM
  2. [SOLVED] VBA for Long Array Formula
    By Dahlia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2018, 07:44 AM
  3. Long Array Formula in VBA (Help)
    By Hozcat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2017, 10:43 AM
  4. [SOLVED] insert long/big formula to cell using VBA
    By wildonln in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-29-2016, 07:33 PM
  5. Insert long formula into range
    By chasmac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2015, 06:22 PM
  6. [SOLVED] Long Formula Array
    By henxan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-04-2014, 09:03 AM
  7. Long Array Formula VBA
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-27-2011, 08:57 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