• Insert Simple “If” formula (2000–VBA)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Insert Simple “If” formula (2000–VBA)

    Author
    Topic
    #360187

    Hi,

    I’m trying to insert a formula into a cell via VBA.

    range(“d2”).Formula = “=IF(C2=”cd”,B2*0.66,B2)”

    But I get this error message: Compile Error! Expected End of Statement.

    What’s wrong?

    Thanks!

    Viewing 0 reply threads
    Author
    Replies
    • #541791

      Just double-up on the double quotes within the formula portion, so that the VB editor knows you want a quote in the formula, instead of ending the line prematurely, like so:

      Range("d2").Formula = "=IF(C2=""cd"",B2*0.66,B2)"
      
    Viewing 0 reply threads
    Reply To: Insert Simple “If” formula (2000–VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: