+ Reply to Thread
Results 1 to 11 of 11

Long Array Formulas Using VBA

  1. #1
    Registered User
    Join Date
    05-01-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    7

    Long Array Formulas Using VBA

    I am trying to get the following long array into a vba sub procedure, however it continues to give the 'cannot set the formula array into the range class' error despite each of the pieces being less than 255 characters. Any help would be appreciated.

    Thanks.

    Please Login or Register  to view this content.
    Last edited by alansidman; 12-20-2013 at 10:32 AM. Reason: code tags added.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Long Array Formulas Using VBA

    I'm not a SendKeys advocate, but I use it to insert long array formulas. Here's the sub and an example of usage:

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Long Array Formulas Using VBA

    BTW, you might build the whole formula as a string and see if it's correct. Your first Replace is going to replace two instances, and the second will replace none.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Long Array Formulas Using VBA

    I dont think it will do all the work, but notice that after
    Please Login or Register  to view this content.
    you have no single occurence of "X_X_X())" because all that used to look like that after first repalce look
    Please Login or Register  to view this content.
    so first try to

    Please Login or Register  to view this content.
    Next: I'd personally work other way - first prepare valid formula as a string and only after having valid formula ready, assign it to a cell. (may be it is worth reconsidering and reconstruct formula, or use some extra region to make partial calculations and make main formula shorter).
    Last edited by Kaper; 12-19-2013 at 02:27 PM.

  5. #5
    Registered User
    Join Date
    05-01-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Long Array Formulas Using VBA

    I ended up doing the following to get the long array entered, but when I went to copy and past the array down the column, I had to enter the copy and paste code into another sub. It works as long as I call them separately, but if I try to put them both in one sub or call one sub with the other, it copies down the exact formula without updating the row numbers and the cell that was copied is no longer an array. Any thoughts as to why this might be?


    Please Login or Register  to view this content.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Long Array Formulas Using VBA

    ''''^''''1
    Last edited by shg; 12-20-2013 at 02:42 AM.

  7. #7
    Registered User
    Join Date
    05-01-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Long Array Formulas Using VBA

    shg--I tried using the code you recommended, but to be honest, I did not understand a lot of what it was doing and could not get it to work in the way that it looks like it was intended which was to enter the array you defined as a constant into cell M1.

    Thanks.

  8. #8
    Registered User
    Join Date
    05-01-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Long Array Formulas Using VBA

    shg, I ended up using a lot of the code that you proposed and it worked in one instance, below:

    Please Login or Register  to view this content.
    However, when I tried the same thing with another formula, I receive a run time 1004 error message regarding the new constant, custrisk. I really appreciate all of the help so far and any insight here, would be a big help.

    Thanks.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Long Array Formulas Using VBA

    Post the workbook?
    Last edited by shg; 12-20-2013 at 02:34 PM.

  10. #10
    Registered User
    Join Date
    05-01-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Long Array Formulas Using VBA

    I updated the insertarrayforumla function to incorporate everything you had in yours and it returns an error--argument not optional, so it seems to be looking for inputs to the other two portions of the function, the xlReferenceStyle and the Optional ByVal. I actually tried guessing some inputs for these and it crashed excel, so I am updating the function again. It seems reasonable that it is looking for the other two arguments, how does it work for you without the last two?

    Thanks again.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Long Array Formulas Using VBA

    Sorry, this line

    Please Login or Register  to view this content.
    should be

    Please Login or Register  to view this content.
    The last argument specifies the reference style of the formula.

    With that change, it worked fine.

+ 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. Array Formulas taking too long to calculate
    By CheeksExcelForum in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-17-2013, 06:56 PM
  2. How can one populate a long array?
    By StevenM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2012, 09:13 AM
  3. Long Array Formula VBA
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-27-2011, 08:57 AM
  4. Codes to long Possible Array may help ?
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-27-2009, 09:11 AM
  5. Array Formulas take waaaay too long...
    By belly0fdesire in forum Excel Formulas & Functions
    Replies: 39
    Last Post: 09-06-2005, 07:05 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