+ Reply to Thread
Results 1 to 6 of 6

Trying to insert formula into cell using ActiveCell.Formula but receiving run-time error

  1. #1
    Registered User
    Join Date
    11-16-2022
    Location
    Los Angeles
    MS-Off Ver
    2022
    Posts
    13

    Trying to insert formula into cell using ActiveCell.Formula but receiving run-time error

    Hello experts,

    I am trying to create a macro that inserts a formula into a cell, but I keep receiving a run-time error '1004' application-defined or object-defined error. I have tried several variations of the ActiveCell.Formula including .FormulaLocal.

    Here is the portion of the code where the error is popping up:


    Sub InsertFormulaIntoCell()

    Range("P10").Select
    ActiveCell.Formula = "=IFERROR((NETWORKDAYS.INTL(M8,O8,1,$Z$2:$Z$13)-(WORKDAY.INTL(M8-1,1,1,$Z$2:$Z$13)<M8)-(WORKDAY.INTL(O8-1,1,1,$Z$2:$Z$13)<O8))*($F$4-$F$3)+MAX(,MOD(O8,1)-$F$3)*(WORKDAY.INTL(O8-1,1,1,$Z$2:$Z$13)<O8)+MAX(,$F$4-MOD(M8,1))*(WORKDAY.INTL(M8-1,1,1,$Z$2:$Z$13)<M8),"")"

    End Sub


    Any advice or recommendations to enable the macro to correctly input this formula without error are greatly appreciated.


    Best Regards,

    Ray
    Attached Files Attached Files
    Last edited by rbaxter89; 11-28-2022 at 03:54 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,204

    Re: Trying to insert formula into cell using ActiveCell.Formula but receiving run-time err

    Try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Trying to insert formula into cell using ActiveCell.Formula but receiving run-time err

    In VBA, "" means empty string, replace it with """".

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,204

    Re: Trying to insert formula into cell using ActiveCell.Formula but receiving run-time err

    Just double up any double quotes ... "" >>> """"

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,204

    Re: Trying to insert formula into cell using ActiveCell.Formula but receiving run-time err

    Thanks for the rep.

  6. #6
    Registered User
    Join Date
    11-16-2022
    Location
    Los Angeles
    MS-Off Ver
    2022
    Posts
    13

    Re: Trying to insert formula into cell using ActiveCell.Formula but receiving run-time err

    Thank you both for the quick responses and solution to my problem, have a good day!

+ 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] Receiving VALUE error in a cell that has this formula
    By cubangt in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-28-2021, 03:01 PM
  2. nested if min formula receiving #VALUE! error
    By whitecastle in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-11-2017, 02:18 PM
  3. Receiving a #REF! error on an INDEX MATCH Formula
    By thomashasler in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-13-2015, 10:51 AM
  4. [SOLVED] Formula Tracking Time In Military Format - Receiving Error
    By DDM64 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-22-2013, 05:24 AM
  5. [SOLVED] Receiving #DIV/0! Error in Basic Formula
    By DDM64 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-10-2013, 11:29 AM
  6. Receiving #NAME? error when adding MONTHS to a formula
    By smsolomon in forum Excel General
    Replies: 2
    Last Post: 02-09-2012, 12:03 PM
  7. ActiveCell.Formula Error
    By Dennis Lavallee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2008, 03:43 PM

Tags for this Thread

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