+ Reply to Thread
Results 1 to 26 of 26

R1C1 syntax

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    R1C1 syntax

    Can someone please help me convert and understand the below formula in R1C1, I am struggling a bit with this. Thank you.

     Const myEpilepsy As String = "=IF(SUMPRODUCT(--(Panel!$B$2:$B$6713=$Q$5),--(Panel!$C$2:$C$6713<=$R$5),--(Panel!$D$2:$D$6713>$R$5)),VLOOKUP($R$5,Panel!$C$2:$E$6713,3,1),""No"")"
    Here is my attempt:
     ActiveCell.FormulaR1C1 = _
    Const myEpilepsy As String = "=IF(SUMPRODUCT(--(Panel!$R[2]$R[2]:$R[6713]$R[2]=Annovar!$R[5]$C[17]),--(Panel!$R[2]$C[3]:$R[6713]$C[3]<=Annovar!$R[5]$C[18]),--(Panel!$R[2]$C[4]:$R[6713]$C[4]>Annovar!$R[5]$C[18])),VLOOKUP(Annovar!$R[5]$C[18],Panel!$R[2]$C[3]:$R[6713]$C[5],3,1),""No"")"
    Last edited by cmccabe; 06-27-2014 at 04:19 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: R1C1 syntax

    R1C1 notation doesn't use $

    R refers to the row containing the formula (a relative reference)

    Ry refers to row y (an absolute reference)

    R[+-y] refers to y rows above/below the cell containing the formula (a relative reference)

    References to columns are symmetric.
    Last edited by shg; 06-27-2014 at 04:28 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: R1C1 syntax

    So if I follow, A1 would be:

    R[1]C[1] - R[1]C[2] = A1 - B1

    R1C1 = A1

    R[2]C[1], R[-1]C[-1] = moving from A2 to A1

    R[2]C[3], R[-1]C[-3] = moving from C2 to A1

    Thanks.
    Last edited by cmccabe; 06-27-2014 at 04:46 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: R1C1 syntax

    R1C1 refers to A1, always and forever, regardless of where it appears, yes. All the others depend on where the formula is entered; they are relative references.

  5. #5
    Registered User
    Join Date
    08-27-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: R1C1 syntax

    Assume you are in C5, that cell is = R5C3. It will always reference that cell its like a $C$5

    If you are in C5 and put in an equation =R[1]C[1] . It will give you the value of D6 (One row positive/down and One column positive/right)
    If you are in C5 and put in an equation =R[-1]C[-1] . It will give you the value of B4 (One row negative/up and One column negative/left)
    If you are in C5 and put in an equation = R3C2. It will give you the value in B3 (Row3 column2)

    (Row,Column)
    A1 = 1,1
    B2 = 2,2
    C10 = 10,3
    Last edited by briguin; 06-27-2014 at 05:27 PM.

  6. #6
    Registered User
    Join Date
    08-27-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: R1C1 syntax

    Panel!$B$2:$B$6713

    Should be

    Panel!R2C2:R6713C2


    Row2 = Row2
    Col2 = B
    Col3 = C
    Col4 = D
    Last edited by briguin; 06-27-2014 at 05:27 PM.

  7. #7
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: R1C1 syntax

    Norie,
    the
      Const myEpilepsy As String = "=IF(SUMPRODUCT(--(Panel!$B$2:$B$6713=$Q$5),--(Panel!$C$2:$C$6713<=$R$5),--(Panel!$D$2:$D$6713>$R$5)),VLOOKUP($R$5,Panel!$C$2:$E$6713,3,1),""No"")"
    is pulling the wrong values.

    It was brought to my attention that R1C1 was needed for VBA.

    In this post, I explain how I know and have the formula that did work, and and attached workbook.
    http://www.excelforum.com/excel-prog...-new-post.html Thank you .

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: R1C1 syntax

    Why do you want to convert the formula to R1C1?
    If posting code please use code tags, see here.

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,430

    Re: R1C1 syntax

    R[1]C[1] - R[1]C[2] = A1 - B1
    If it will help, I would point out that the relative reference R[1]C[1] can never refer to A1. A1 (R1C1) is the leftmost, topmost cell in a sheet. There cannot be a cell 1 row above and 1 column to the left of A1 (R1C1). It is not possible to have a relative R1C1 reference with positive offsets (positive numbers inside the []'s) that refers to A1.

    If that made sense to you, then you are well on your way to understanding R1C1 references. If that created more confusion, then you still have a ways to go in understanding how these work.

    R[2]C[1], R[-1]C[-1] = moving from A2 to A1
    R[2]C[3], R[-1]C[-3] = moving from C2 to A1
    Another thing I would point out is that R1C1 references, when copied, do not "change" -- the formula text looks exactly the same as it did in the original cell.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  10. #10
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: R1C1 syntax

    Thank you that is very helpful .

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: R1C1 syntax

    If it will help, I would point out that the relative reference R[1]C[1] can never refer to A1.
    Umm -- yes it can, if it's in the bottom right corner of the sheet.

  12. #12
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,430

    Re: R1C1 syntax

    Quote Originally Posted by shg View Post
    Umm -- yes it can, if it's in the bottom right corner of the sheet.
    Having never had a spreadsheet large enough to even consider this possibility, I always thought it was impossible. I did not realize these references could "wrap around". With Winnie the Pooh, I declare myself "foolish and deluded, and a bear of no brain at all."

    I would modify my conclusion to, if you can understand how the wrap around works, you are well on your way to understanding how R1C1 relative references work.

  13. #13
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: R1C1 syntax

    Hmm, I have no idea whats wrong with the formula.

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: R1C1 syntax

    That's wrong, R1C1 is not needed for VBA.

    The formula may not be working but converting it to R1C1 isn't going to make any difference.

    PS Did you every try changing $R$5, $Q$5 etc do $R5, $Q5 etc as I suggested - think I even posted code with those references changed.

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: R1C1 syntax

    Have you tried stepping through it?

    You can do that by selecting a cell with the formula in it, preferably one that's not giving the correct result, and going to the Formulas tab and clicking Evaluate Formula.

  16. #16
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: R1C1 syntax

    Formula that worked when the values were all on 1 sheet
     =IF(COUNTIFS( A$2:A$6713,F5,B$2:B$6713,"<="&G5,C$2:C$6713, ">="&G5),VLOOKUP(G5,$B$2:$D$6713,3,1),"No")
    I can step through all the way to the evaluation of this (6C) (which is correct)

    the code in the VBA:

    =IF(SUMPRODUCT(--(panel!$B$2:$B$6713=$Q$5),--(panel!$C$2:$C$6713<=$R$5),--(panel!$D$2:$D$6713>$R$5)),VLOOKUP($R$5,panel!$C$2:$E$6713,3,1),"No")
    I attached an imaage of the evaluate.

    Thanks.
    Attached Files Attached Files

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,433

    Re: R1C1 syntax

    It was brought to my attention that R1C1 was needed for VBA.
    Yes and no. If your code says Range(...).FormulaR1C1 = then, yes! it will require a formula in R1C1 format. If, however, it says .Formula = then, no, it can be a formula as you would type it in the cell. In both cases, give or take. If you have any constants in quotes, you will need to double up the quotes.

    In the original post, I think you should forget about the Const and just have:

    ActiveCell.Formula = _
          "=IF(SUMPRODUCT(--(Panel!$B$2:$B$6713=$Q$5),--(Panel!$C$2:$C$6713<=$R$5),--(Panel!$D$2:$D$6713>$R$5)),VLOOKUP($R$5,Panel!$C$2:$E$6713,3,1),""No"")"

    Note that VLOOKUP with fourth parameter of 0 or FALSE is required for an EXACT match.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: R1C1 syntax

    The formula that works is completely different from the formula in the code.

  19. #19
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,433

    Re: R1C1 syntax

    I don't understand. They are two completely different formulae. Nothing to do with whether or not it's on the same sheet. You've changed COUNTIFS to SUMPRODUCT and you have even changed the cells you compare.

    No surprise it doesn't give the same result.

    Regards, TMS

  20. #20
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: R1C1 syntax

    Below is the entire Code, if I change the SUMPRODUCT to COUNTIFS then the underlined line of code throws an erorr- application or object-defined. Thanks.

     Sub Calculations()
    Dim l As Long
    Dim Res As Variant
    
        Res = Application.VLookup(Range("A2").Value, Range("CA:CF"), 6, 0)
    
        Const myEpilepsy As String = "=IF(SUMPRODUCT(--(Panel!$B$2:$B$6713=$Q$5),--(Panel!$C$2:$C$6713<=$R$5),--(Panel!$D$2:$D$6713>$R$5)),VLOOKUP($R$5,Panel!$C$2:$E$6713,3,1),""No"")"
        Const myMarfan As String = "=IF(SUMPRODUCT(--(Panel!$B$25610:$B$29333=$Q$5),--(Panel!$C$25610:$C$29333<=$R$5),--(Panel!$D$25610:$D29333>$R$5)),VLOOKUP($R$5,Panel!$C$25610:$E$29333,3,1),""No"")"
    
        If Not IsError(Res) Then
             l = Sheets("annovar").Range("A" & Rows.Count).End(xlUp).Row
             
            Select Case Res
                Case "Comprehensive Epilepsy"
                    Sheets("annovar").Range("AQ5:AQ" & l).Formula = myEpilepsy                 
                Case "Marfan Disorder"
                   Sheets("annovar").Range("AQ5:AQ" & l).Formula = myMarfan
            End Select
    
    End If
    End Sub

  21. #21
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,433

    Re: R1C1 syntax

    You can't just change from COUNTIFS to SUMPRODUCT. The structure of the functions are different.

  22. #22
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: R1C1 syntax

    SUMPRODUCT and COUNTIFS are not interchangeable.

    You might be able to substitute one for the other, but not without making significant changes.

    How exactly are you changing the formula?

  23. #23
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: R1C1 syntax

    I just tried changing the sumproduct to countifs, as I do not know much about vba and formulas, what do you suggest. Thanks

  24. #24
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,433

    Re: R1C1 syntax

    I'd suggest you look up the Help for both formulae and compare the structures. Also, check the parameters for VLOOKUP while you're at it.

  25. #25
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: R1C1 syntax

    Thank you.

  26. #26
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,433

    Re: R1C1 syntax

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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] R1C1 Syntax issue
    By jsuarez199 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-11-2013, 08:44 AM
  2. Updating formulas using R1C1 syntax
    By lfeder in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2013, 04:06 PM
  3. Syntax to add a variable for Row Number in R1C1 format
    By Jon.R in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-09-2011, 10:29 AM
  4. 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
  5. [SOLVED] R1C1
    By Arne Hegefors in forum Excel General
    Replies: 1
    Last Post: 08-18-2006, 05:15 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