Consulting

Results 1 to 5 of 5

Thread: Help needed with to input formula with vba

  1. #1
    VBAX Regular
    Joined
    May 2004
    Location
    UK
    Posts
    71
    Location

    Help needed with to input formula with vba

    i need a bit of help to insert a formula into a worksheet by the use of vba, when i try to do it i get an error, here ie the bit of code i am trying with


    Range("aa6").formulaR1C1 = "=IF(E6="agy","",IF(E6="o/t","",IF(COUNT(F6,G6)=2,(H6-F6+(H6<F6))*24-0.75,"")))"
       Range("aa6:ac250").FillDown

    I get the error on the red text, i get a message box saying compile error,expected end of statment

    Thank you for any help

    Ian

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Ian,

    To include quote characters in a quoted string, you must double them up ..

    Range("aa6").formulaR1C1 = "=IF(E6=""agy"","""",IF(E6=""o/t"","""",IF(COUNT(F6,G6)=2,(H6-F6+(H6<F6))*24-0.75,"""")))"
    Range("aa6:ac250").FillDown
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    VBAX Regular
    Joined
    May 2004
    Location
    UK
    Posts
    71
    Location
    Thanks for that tony.
    That works ok, i did have to change the formulaR1C1 section to formula for it to work properly.

    I did realise that i had put it in the wrong section, and i tried to delete it and do it again in the right place but could not find out how to delete a post.


    Thanks

    Ian

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    No problem, Ian.

    Some fool, sorry, excellent administrator gave me special priveleges here so I can do things ordinary mortals can't.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Only the great and the good get to hide their mistakes, which is why they are infallible!
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •