+ Reply to Thread
Results 1 to 3 of 3

Array formula in a macro

  1. #1
    Registered User
    Join Date
    12-18-2014
    Location
    germany
    MS-Off Ver
    2010
    Posts
    1

    Array formula in a macro

    Hi everybody,

    I’m not an expert in vba, I have to write a macro that calculate a long array formula in a cell. I wrote:

    Cells(2, LastCol + 1).Select
    Selection.FormulaArray = "=IF(ISERROR(INDEX('[file.xlsx]Sheet'!R3C6:R23C8,MATCH(RC[-164]&RC[-159],'[file.xlsx]Sheet'!R3C7:R23C7&'[file.xlsx]Sheet'!R3C6:R23C6,0),3)),VLOOKUP(RC[-159],'[file.xlsx]Sheet'!R3C2:R29C3,2,0),INDEX('[file.xlsx]Sheet'!R3C6:R23C8,MATCH(RC[-164]&RC[-159],'[file.xlsx]Sheet'!R3C7:R23C7&'[file.xlsx]Sheet'!R3C6:R23C6,0),3))"

    But I get the tipical error message:

    Run-time error ‘1004’:
    Application-defined or object-defined error

    The funny thing is that if I use the same formula with Selection.FormulaR1C1 = at the beginning of the line it works (but unfortunately is then not defined as array formula)

    Any suggestion?
    Thanks a lot

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Array formula in a macro

    my guess is you can't use RC formatting when not using FormulaR1C1...so you have to convert your RC references to something else...without seeing all the data I can't tell you what that would be...
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Array formula in a macro

    Hi zerog,

    I have very little exposure to array formulas. However, the following link may help you: https://colinlegg.wordpress.com/2012...aarray-in-vba/

    Lewis

+ 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. Macro which replace large array formula
    By ALEZI in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2014, 02:32 PM
  2. VBA Macro: Plugging an Array-Formula into a Cell and Dragging Formula Down Columns
    By Brianandstewie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-20-2013, 02:57 PM
  3. Macro to Insert Formula Array
    By samikusi in forum Excel General
    Replies: 0
    Last Post: 06-11-2012, 01:14 PM
  4. array formula macro
    By '''your code here in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-14-2011, 07:42 PM
  5. inserting formula array with macro
    By Pasha81 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-28-2009, 06:20 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