+ Reply to Thread
Results 1 to 9 of 9

FormulaR1C1 to Write a Formula Question

  1. #1
    Registered User
    Join Date
    02-08-2017
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    77

    FormulaR1C1 to Write a Formula Question

    Hello,

    I am trying to use VBA to insert formulas in different cells in my worksheet but am having some issues. Here is what I have so far and what issues I am seeing.

    What I want to do is insert a formula into H2 that is = G2*1.01 but I want it to leave the formula in the cell.

    1) When I use, Range("H2").Formula = "G2*1.01" it calculates this correctly, but it does not leave the formula in the cell.

    2) When I use, Range("H2").FormulaR1C1 = "=R2C7 * 1.01" it leaves the formula in the cell, but it leaves it as $G$2 *1.01 which I also don't want.

    3) When I use, Range("H2").FormulaR1C1 = "=R[2]C[7] * 1.01" it does exactly what I want, except the formula that it returns is O4 *1.01. Somehow it took R[2]C[7] and turned it into O4....

    Any help would be appreciated!

    Thanks

    Yoandsm

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: FormulaR1C1 to Write a Formula Question

    Give this a try...

    Please Login or Register  to view this content.
    HTH
    Regards, Jeff

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: FormulaR1C1 to Write a Formula Question

    In VBA .FormulaR1C1 when using relative reference, must be relative to the cell where the formula is being entered to.

    So for H2 referencing G2... since G column is 1 column to left of H, but remaining in same row.
    Please Login or Register  to view this content.
    Last edited by CK76; 06-01-2018 at 11:04 AM. Reason: I had G & H reversed in explanation
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Registered User
    Join Date
    02-08-2017
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    77

    Re: FormulaR1C1 to Write a Formula Question

    That worked! Thank you! That was evidently the one combination that I didn't try...

    You're the best!

  5. #5
    Registered User
    Join Date
    02-08-2017
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    77

    Re: FormulaR1C1 to Write a Formula Question

    That makes sense now! Thank you very much!

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: FormulaR1C1 to Write a Formula Question

    You are very welcome. We are happy to help.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: FormulaR1C1 to Write a Formula Question

    You are welcome and thanks for the rep

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: FormulaR1C1 to Write a Formula Question

    It is difficult to see what difficulty you are having. jeffreybrown's suggestion might be the final solution for what you are after, so my post may be superfluous (ignore, in that case).

    The main problem I see is that you are not understanding how relative references work in R1C1 notation. This provides a good explanation of R1C1 referencing (along with other reference types: https://support.office.com/en-us/art...es_in_formulas ).

    R[x]C[y] references are relative references that show how far to go from the formula cell to retrieve data. R[2]C[7] in H2 (R2C8) means "go down +2 rows and to the right +7 columns" which is R4C15 or O4. To get "same row 1 column to the left (-1 column to the right)" you use R[0]C[-1]. The [0] is optional, and Excel will enter it as RC[-1].
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  9. #9
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: FormulaR1C1 to Write a Formula Question

    @MrShorty,

    I think the original problem could have been a missing equal sign.

    1) When I use, Range("H2").Formula = "G2*1.01" it calculates this correctly, but it does not leave the formula in the cell.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Adopting Excel formula to VBA FormulaR1C1
    By drrazor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2014, 11:08 AM
  2. Having trouble writing a formula with FormulaR1C1
    By octaviogro in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-10-2013, 06:01 PM
  3. Using FormulaR1C1 to input complex formula into cell
    By kevnin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-09-2008, 07:51 PM
  4. [SOLVED] Write an Excel Formula Question
    By Kathleen_klr in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-04-2006, 02:47 PM
  5. [SOLVED] IF formula question:LOTS clearer to write it
    By Rubix in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-08-2006, 03:40 AM
  6. [SOLVED] Formula question-how I should write it?
    By Dawn in forum Excel General
    Replies: 1
    Last Post: 11-08-2005, 03:00 PM
  7. How to write script for a question
    By PeterG in forum Excel General
    Replies: 0
    Last Post: 02-22-2005, 10:45 AM

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