+ Reply to Thread
Results 1 to 7 of 7

how to insert formula in VBA

  1. #1
    Forum Contributor
    Join Date
    06-04-2006
    Posts
    132

    how to insert formula in VBA

    Hi,

    I'm having problem with inserting formula into cells in VBA. I was trying to get some idea by using macro recording.

    I got the following
    ActiveCell.FormulaR1C1 = "=R[-1]C[-1]+RC[-1]"

    but i don't understand this.

    I suppose what i'm trying to do is be able to insert the formula in some cells.

    for example: =B5-A5 -> inserted into cell "C5"

    Thank you in advance

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    This is OTT but give you an idea on setting ranges etc

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by associates
    Hi,

    I'm having problem with inserting formula into cells in VBA. I was trying to get some idea by using macro recording.

    I got the following
    ActiveCell.FormulaR1C1 = "=R[-1]C[-1]+RC[-1]"

    but i don't understand this.

    I suppose what i'm trying to do is be able to insert the formula in some cells.

    for example: =B5-A5 -> inserted into cell "C5"

    Thank you in advance
    Hi,

    just use the obvious,

    Range("C5").Fornula = "=B5-A5"

    or

    Range("C5:C25").Formula = "=B5-A5"

    or

    Range("C5:C25").Formula = "=B$5-A5"


    hth
    ---
    Last edited by Bryan Hessey; 11-21-2006 at 03:37 AM.
    Si fractum non sit, noli id reficere.

  4. #4
    Registered User
    Join Date
    04-01-2012
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: how to insert formula in VBA

    can someone help me with this code, please

    Please Login or Register  to view this content.
    Last edited by arlu1201; 01-10-2013 at 01:59 AM.

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: how to insert formula in VBA

    titubd,

    Welcome to the forum.

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.

    Also,

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  6. #6
    Valued Forum Contributor
    Join Date
    09-04-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    463

    Re: how to insert formula in VBA

    paste the following code in which sheet you want to get your data.

    Please Login or Register  to view this content.
    Regards
    CA Mahaveer Somani
    Last edited by arlu1201; 01-10-2013 at 04:23 AM.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: how to insert formula in VBA

    Mahaveer,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.

+ 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