+ Reply to Thread
Results 1 to 6 of 6

Long Formula Getting 1004 error when running VBA

  1. #1
    Registered User
    Join Date
    08-14-2015
    Location
    UK
    MS-Off Ver
    2013
    Posts
    10

    Long Formula Getting 1004 error when running VBA

    I am trying to insert a formula into a cell as part of a Macro and it keep giving my a 1004 error but I can't figure out why. Any help would be greatly received. code below

    ActiveCell.FormulaR1C1 = _
    "=((((SUMIFS(Data!C5,Data!C13,RC3,Data!C1,"">=""&R4C3,Data!C1,""<=""&R4C4,Data!C19,R5C))/R19C)*(SUMIFS(Data!C5,Data!C13,""Other Leave"",Data!C1,"">=""&R4C3,Data!C1,""<=""&R4C4,Data!C19,R5C)))+((((SUMIFS(Data!C5,Data!C13,RC3,Data!C1,"">=""&R4C3,Data!C1,""<=""&R4C4,Data!C19,R5C))/R19C)*(SUMIFS(Data!C5,Data!C13,""Holiday"",Data!C1,"">=""&R4C3,Data!C1,""<=""&R4C4,Data!C1" & _
    "+((((SUMIFS(Data!C5,Data!C13,RC3,Data!C1,"">=""&R4C3,Data!C1,""<=""&R4C4,Data!C19,R5C))/R19C)*(SUMIFS(Data!C5,Data!C13,""Sick Leave"",Data!C1,"">=""&R4C3,Data!C1,""<=""&R4C4,Data!C19,R5C)))+(SUMIFS(Data!C5,Data!C13,RC3,Data!C1,"">=""&R4C3,Data!C1,""<=""&R4C4,Data!C19,R5C)))))"

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Long Formula Getting 1004 error when running VBA

    One way to check it would be to put the formula into a cell manually and test it until it is good.
    Then recored a macro of you entering the formula.
    (Press RecordMacro, select the cell with the good formula, put the cursor in the edit box, press enter, press Stop Recording.)

    That recorded macro will give you the formula string without extra commas etc., then copy/paste that string into your VBA routine.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    08-14-2015
    Location
    UK
    MS-Off Ver
    2013
    Posts
    10

    Re: Long Formula Getting 1004 error when running VBA

    Thanks for the quick reply. I did what you suggested to get the formula.
    When the formula is typed into the cell it works fine its just when the Macro is running that I get the error. I've pasted the formula I'm using below in case it helps.
    =((((SUMIFS(Data!$E:$E,Data!$M:$M,$C6,Data!$A:$A,">="&$C$4,Data!$A:$A,"<="&$D$4,Data!$S:$S,D$5))/D$20)*(SUMIFS(Data!$E:$E,Data!$M:$M,"Other Leave",Data!$A:$A,">="&$C$4,Data!$A:$A,"<="&$D$4,Data!$S:$S,D$5)))+((((SUMIFS(Data!$E:$E,Data!$M:$M,$C6,Data!$A:$A,">="&$C$4,Data!$A:$A,"<="&$D$4,Data!$S:$S,D$5))/D$20)*(SUMIFS(Data!$E:$E,Data!$M:$M,"Holiday",Data!$A:$A,">="&$C$4,Data!$A:$A,"<="&$D$4,Data!$S:$S,D$5)))+((((SUMIFS(Data!$E:$E,Data!$M:$M,$C6,Data!$A:$A,">="&$C$4,Data!$A:$A,"<="&$D$4,Data!$S:$S,D$5))/D$20)*(SUMIFS(Data!$E:$E,Data!$M:$M,"Sick Leave",Data!$A:$A,">="&$C$4,Data!$A:$A,"<="&$D$4,Data!$S:$S,D$5)))+(SUMIFS(Data!$E:$E,Data!$M:$M,$C6,Data!$A:$A,">="&$C$4,Data!$A:$A,"<="&$D$4,Data!$S:$S,D$5)))))
    Last edited by johnmahon12; 05-24-2016 at 10:25 AM.

  4. #4
    Registered User
    Join Date
    08-14-2015
    Location
    UK
    MS-Off Ver
    2013
    Posts
    10

    Re: Long Formula Getting 1004 error when running VBA

    I've also tried shortening it by using named ranges but still no joy.

    =((((SUMIFS(T,P,RC3,D,"">=""&R4C3,D,""<=""&R4C4,N,R5C))/R20C)*(SUMIFS(T,P,""Other Leave"",D,"">=""&R4C3,D,""<=""&R4C4,N,R5C)))+((((SUMIFS(T,P,RC3,D,"">=""&R4C3,D,""<=""&R4C4,N,R5C))/R20C)*(SUMIFS(T,P,""Holiday"",D,"">=""&R4C3,D,""<=""&R4C4,D+(SUMIFS(T,P,RC3,D,"">=""&R4C3,D,""<=""&R4C4,N,R5C))))"

  5. #5
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: Long Formula Getting 1004 error when running VBA

    Are you using .Formula or .FormulaArray?

    The length of this would suggest it is an array and should be set as such rather than just a formula

  6. #6
    Registered User
    Join Date
    08-14-2015
    Location
    UK
    MS-Off Ver
    2013
    Posts
    10

    Re: Long Formula Getting 1004 error when running VBA

    I'm using .formula
    its not an array formula.

+ 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] error 1004 when running macro
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-14-2016, 02:00 PM
  2. Replies: 1
    Last Post: 03-12-2014, 12:42 PM
  3. 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
  4. Run-Time error '1004': when running my code
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-11-2012, 03:19 PM
  5. Run-Time Error 1004 running macro
    By LeaLeaLaLa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2010, 12:51 PM
  6. runtime 1004 error - string to long
    By SarahPintal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2009, 02:55 AM
  7. Code too long? Error 1004
    By mole2704 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2008, 07:25 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