+ Reply to Thread
Results 1 to 2 of 2

.FormulaArray causes Run Time Error 1004, Unable to set the FormulaArray property

Hybrid View

dluhut .FormulaArray causes Run Time... 07-26-2017, 02:04 PM
xladept Re: .FormulaArray causes Run... 07-28-2017, 03:12 PM
  1. #1
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,132

    .FormulaArray causes Run Time Error 1004, Unable to set the FormulaArray property

    Hello,

    In the Excel file, the formula array is

    {=SUM(IF($A152='\\network drive full path\[Excel File Name.xlsx]Sheet Name'!$AG:$AG,'\\network drive full path\[Excel File Name.xlsx]Sheet Name'!Q:Q,0))}
    .

    The macro that I've created is basically assigning the range, i.e $AG:$AG and/or Q:Q to $AG1:$AG5000 and/or Q1:Q5000 respectively.

    Below is my macro and when check the result in the 'Immediate' Window, it's correct.

    I even went and manually use the result from the 'Immediate' Window and paste it to the formula bar and Ctr + Shift + Enter and return no error.

    Result from the 'Immediate' Window.

    =SUM(IF($A152='\\network drive full path\[Excel File Name.xlsx]Sheet Name'!$AG1:$AG5000,'\\network drive full path\[Excel File Name.xlsx]Sheet Name'!Q1:Q5000,0))
    But for some reason, VBA just throw me an error.

    May I know what's wrong with it.

    formulaText = currWS.Range("I" & rowToLoop).Formula
    
    SumIfFormulaToKeep = Mid(formulaText, InStr(formulaText, "SUM(IF"), InStr(formulaText, "!") - InStr(formulaText, "SUM(IF") + 1)    'Result in SUM(IF($A152='\\network drive full path\[Excel File Name.xlsx]Sheet Name'!
    SumIfFormulaChar = Mid(formulaText, InStr(formulaText, "!") + 2, InStr(formulaText, ":") - InStr(formulaText, "!") - 2)                     'Result in AG
                                
    SumIfTrueFormulaToKeep = Mid(formulaText, InStrRev(formulaText, ",'\\baxter") + 1, InStrRev(formulaText, "!") - InStrRev(formulaText, ",'\\network"))   'Result in '\\network drive full path\[Excel File Name.xlsx]Sheet Name'!
    SumIfTrueFormulaChar = Mid(formulaText, InStrRev(formulaText, "!") + 1, InStrRev(formulaText, ":") - InStrRev(formulaText, "!") - 1)                             'Result in Q
                                
    correctedSumIfFormula = "=" & SumIfFormulaToKeep & "$" & SumIfFormulaChar & "1:$" & SumIfFormulaChar & "5000," & SumIfTrueFormulaToKeep & SumIfTrueFormulaChar & "1:" & SumIfTrueFormulaChar & "5000,0))"   'Result in =SUM(IF($A152='\\network drive full path\[Excel File Name.xlsx]Sheet Name'!$AG1:$AG5000,'\\network drive full path\[Excel File Name.xlsx]Sheet Name'!Q1:Q5000,0))
                                
    currWS.Range("I" & rowToLoop).FormulaArray = correctedSumIfFormula   <--- This is the error that's highlighted

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: .FormulaArray causes Run Time Error 1004, Unable to set the FormulaArray property

    This looks to be like your problem.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ 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] Run-time error '1004': Unable to set the FormulaArray property of the Range class
    By billj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-24-2017, 10:30 AM
  2. Error on unable to set FormulaArray Property
    By Matthewious2016 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2016, 09:48 PM
  3. 1004: Unable to set the FormulaArray property of the Range class
    By drrazor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2015, 11:39 AM
  4. long formula to vba macro - error 1004 unable to set formulaarray property
    By desibabuji in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-08-2013, 06:18 AM
  5. unable to set FormulaArray property of Range Class Error
    By BuglerX in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 11-23-2011, 01:13 PM
  6. unable to set FormulaArray property of Range class Error
    By BuglerX in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-23-2011, 12:14 PM
  7. Unable to set the FormulaArray Property of the Range Class - Error 1004
    By manchmal2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2010, 05:08 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