+ Reply to Thread
Results 1 to 9 of 9

Thread: FormulaR1C1 and Variable.

  1. #1
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    FormulaR1C1 and Variable.

    No matter what I do I still can't get my head around variables and formulas.

    I am trying to reference Row -117 by using a positive variable value.
    The variable LR = 100 in this example, any help would be appreciated.

    The top code is the straight formula.
    .FormulaR1C1 = "=COUNTIF( R[-117]C:R[-1]C,""Yes"")"
    .FormulaR1C1 = "=COUNTIF( R[" & -LR - 17 & "]C:R[-1]C,""Yes"")"
    Last edited by JapanDave; 01-24-2012 at 06:28 AM.
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

  2. #2
    Valued Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    276

    Re: FormulaR1C1 and Variable.

    and what seems to be the problem? What cell are you trying to enter this formula into?

  3. #3
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: FormulaR1C1 and Variable.

    Your second example works fine for me ...
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    Re: FormulaR1C1 and Variable.

    Hey shg, the second example runs fine, but it does not give the row offset value of -117, it gives me a value of -51???

    Edit: I am placing the formula in Row 135 to count values from row 17 to 134.
    Last edited by JapanDave; 01-23-2012 at 05:01 PM.
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

  5. #5
    Valued Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    276

    Re: FormulaR1C1 and Variable.

    Quote Originally Posted by Firefly2012 View Post
    What cell are you trying to enter this formula into?
    You are entering a formula with relative references, so I ask again, what cell are you entering this formula into? Row 168 by any chance?

  6. #6
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    Re: FormulaR1C1 and Variable.

    It is in my last post.
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

  7. #7
    Valued Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    276

    Re: FormulaR1C1 and Variable.

    Then LR doesn't equal 100 when the line of code is executed - can you place a breakpoint on this line and run the code and then see what value LR is when this line is executed?

  8. #8
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: FormulaR1C1 and Variable.

    The way I solve problems like this is to set a breakpoint at the line of interest, then copy the string to the Immediate window:

    ? "=COUNTIF( R[" & -LR - 17 & "]C:R[-1]C,""Yes"")"
    Press Enter, and I saw:

    =COUNTIF( R[-117]C:R[-1]C,"Yes")
    ... as expected. As I said, it worked fine for me, Dave. Want to post a simple workbook with an example that fails?
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    Re: FormulaR1C1 and Variable.

    Quote Originally Posted by Firefly2012 View Post
    Then LR doesn't equal 100 when the line of code is executed
    shg & Firefly, your right it does work, my math skills don't however. Firefly, the moment I read your post I new a few lines ahead of this line that I changed the LR variable value.

    Ahh, I have at this piece of code too long.

    @ shg, thanks for the tip on the Immediate window, I would never have thought to use that.

    Thanks guys.
    Dave
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

+ 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.2.0