Urgent help I want my VB script to insert an excell formula in a specified excel cell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nicoPK
    New Member
    • Dec 2010
    • 2

    #1

    Urgent help I want my VB script to insert an excell formula in a specified excel cell

    The formula is: =IF(Input!R703< 0,HPLNK(Input!R 703,Entity,Cate gory6,$A$677&". "&$A703,N$3,Fre quency1,Applica tion1),HPLNK(In put!R703,Entity ,Category6,"P17 09"&"."&$A703,N $3,Frequency1,A pplication1))
    This works fine is excel so I know the syntax is ok with Excel

    When I try this in VB:
    Range("N679").S elect
    Selection.Formu la = "=IF(Input!R679 <0,HPLNK(Input! R679,Entity,Cat egory6,$A$677&" ."&$A679,N$3,Fr equency1,Applic ation1),HPLNK(I nput!R679,Entit y,Category6,"P1 709"&"."&$A679, N$3,Frequency1, Application1))"

    I get a compile error with syntax

    Can anyone help?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Try writing the formula to the cell as a string.
    Code:
    Range("N679") = "IF(Input!R703<0,HPLNK(Input!R703,Entity,Category6 ,$A$677&"."&$A703,N$3,Frequency1,Application1),HPL NK(Input!R703,Entity,Category6,"P1709"&"."&$A703,N $3,Frequency1,Application1))"
    The code I've posted won't work without modification.
    But I have written formulas as strings to Excel with no problems.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      You didn't escape the double quotes in your string.
      Error> "a & "b" & c"
      Correct> "a & ""b"" & c"

      Comment

      • nicoPK
        New Member
        • Dec 2010
        • 2

        #4
        spot on Rabbit - thanks for your help

        Comment

        Working...