+ Reply to Thread
Results 1 to 4 of 4

Problem inserting a function from VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    09-18-2006
    Posts
    2

    Problem inserting a function from VBA

    Hi

    I have the following code in VBA

    MyFormula = "=IF(E10="""";F9;F9+E10)"
    Range(Cells(Row + 2, 5), Cells(Row + 2, 5).Value = MyFormula

    When executed I get Run-time error '1004'
    Application-defined or object-defined error

    If I change MyFormula to "=F8+F9" then it works OK.

    MyFormula is created in the VBA routine.

    Can it be done ??

    Thanks in advanced for any help.

    Tage

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try so:
    MyFormula = "=IF(E10="""",F9,F9+E10)"
    Range(Cells(Row + 2, 5), Cells(Row + 2, 5)).Value = MyFormula

    it seems good

  3. #3
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Perhaps

    =IF(ISBLANK(E9),E10,E9+E10)

    might serve your purposes better than what I presume you meant to be

    =IF(E10="",F9,F9+E10)


    the ; appear to be the source of your error.

    ---
    Quote Originally Posted by tagen
    Hi

    I have the following code in VBA

    MyFormula = "=IF(E10="""";F9;F9+E10)"
    Range(Cells(Row + 2, 5), Cells(Row + 2, 5).Value = MyFormula

    When executed I get Run-time error '1004'
    Application-defined or object-defined error

    If I change MyFormula to "=F8+F9" then it works OK.

    MyFormula is created in the VBA routine.

    Can it be done ??

    Thanks in advanced for any help.

    Tage

  4. #4
    Registered User
    Join Date
    09-18-2006
    Posts
    2
    You're right antoka05, changing the ; to , did the trick.
    I used the ; because when entering the IF function in the spreadsheet I have to used ; - , is used for decimal-point and I just looked at the syntax in the spreadsheet.

    Thanks for quick answer.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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