+ Reply to Thread
Results 1 to 8 of 8

Proper syntax for R1C1 formula in VBA

  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    Atlanta Ga
    MS-Off Ver
    Excel 2007
    Posts
    12

    Question Proper syntax for R1C1 formula in VBA

    Let's try this again!

    I posted this yesterday but it didn't come out right and I did not add code tags because I wasn't sure how...

    Anyway, I still would appreciate help!

    I am trying to figure out how to make this code below enter a PERCENTILE formula in another cell using variables that change depending on the currently Active Cell

    Please Login or Register  to view this content.
    If the formula is manually entered on the worksheet at range F11621 as =PERCENTILE(C11621:C18620,0.95) it works as intended...
    How should the formula that is highlighted above be coded to use the row and column numbers obtained from the variables?
    The first part RC[-3]: works fine but I don't know how to use the right syntax to add the variable for Row2nd which in this instance should be C18060

  2. #2
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Proper syntax for R1C1 formula in VBA

    u can use R[6999]C[-3] for C18620

    Please Login or Register  to view this content.
    btw, in this case, if you record a macro while filling the formula, it will generate the vba for you

    cheers,
    Rick
    Last edited by rkey; 08-27-2015 at 08:24 AM. Reason: 18620 in stead of 18060

  3. #3
    Registered User
    Join Date
    01-22-2013
    Location
    Atlanta Ga
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Proper syntax for R1C1 formula in VBA

    Thanks soooo much Rick, it works beautifully...
    Now if I only understood why the R[6999] part works???
    Thanks again!

  4. #4
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Proper syntax for R1C1 formula in VBA

    ....you use the C18620 in your formula, while your question is about C18060 (and my answer mixed them both to )

    It works quite simple, just do 11621 + 6999 = 18620. Basicly a positive number brings you a row lower in your sheet, compared to the cell where the fomula is in and a negative one will bring you up.

  5. #5
    Registered User
    Join Date
    01-22-2013
    Location
    Atlanta Ga
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Proper syntax for R1C1 formula in VBA

    That makes sense now!

    Thanks again!!!

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

    Re: Proper syntax for R1C1 formula in VBA

    Quick primer on R1C1 notation:

    R[i]c[j]: Brackets are for relative references. This means i rows away and j columns away from this cell. If i is negative, it means above, positive below. Negative j refers to columns to the left, positive j is going right.

    RiCj: Without brackets means absolute reference to row i and column j.

    So....
    RC[-3] -- refers to the cell in the same row and 3 columns to the left.
    R[6999]C[-3] -- refers to the cell 6999 rows below and 3 columns to the left.
    The same range with absolute references would be R11621C3:R18620C3
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Registered User
    Join Date
    01-22-2013
    Location
    Atlanta Ga
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Proper syntax for R1C1 formula in VBA

    It's Still not quite right...

    The responses given above work but the number (6999) changes or varies depending on the the range size of a particular data set. (and there are numerous data sets in this large worksheet)
    That's why I need to use variables to find the beginning and ending row numbers. The total number of rows varies with each data set. So the question still is how can I pass a variable to the formula instead of the highlighted static number 6999 below.
    What's the correct syntax?


    Please Login or Register  to view this content.
    I've tried numerous ways to get the syntax right with no luck, but I'm sure there's a way to do it...

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

    Re: Proper syntax for R1C1 formula in VBA

    The formula is just a text string, so, to use a variable as part of that text string, you simply need to use text manipulation (in particular, the concatenation operator &) to put the text string together. Should be something like:
    Please Login or Register  to view this content.

+ 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. Help with proper syntax for an IF(AND formula construct
    By indians207 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 06-09-2017, 03:39 PM
  2. Proper formula syntax for an AND statement?
    By redsab in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-21-2013, 10:58 AM
  3. Proper syntax for EV(Expected Value) formula
    By Noobraino in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-20-2012, 09:01 PM
  4. Proper syntax for a time formula
    By nicolelschramartin in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 12-07-2012, 07:16 PM
  5. Proper syntax to shorten Countif formula
    By small_wonder in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-01-2012, 09:23 AM
  6. [SOLVED] Proper syntax with formula in VBA
    By kcleere in forum Excel General
    Replies: 3
    Last Post: 09-06-2012, 10:44 AM
  7. Help with Syntax Using R1C1 in VBA
    By nofzinger in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2010, 11:38 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