+ Reply to Thread
Results 1 to 3 of 3

Absolute reference with VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    11-06-2007
    Posts
    48

    Absolute reference with VBA

    I searched the forum but i did not see anything to help me understand how to fix this.
    I want to copy a formula with an absolute reference to a range.

    The reference that should be absolute is R[1]C[0]. It can either be $K$3 or the cell selected in the first line of the code.
    Any help appreciated ,
    Thanks

    Range("g3").End(xlDown).Offset(0, 3).Select
    ActiveCell.Value = Range("K3").Value
    ActiveCell.FormulaR1C1 = "=R[1]C[0]-RC[-2]+RC[-1]"
    Selection.Copy
    Range(Selection, "J3").Select
    ActiveSheet.Paste

  2. #2
    Registered User
    Join Date
    11-06-2007
    Posts
    48
    I figured it out by doing the following. Thanks
    Range("g3").End(xlDown).Offset(0, 3).Select
    ActiveCell.Value = Range("K3").Value
    ActiveCell.Formula = "=" & (ActiveCell.Offset(1, 0).Address) & "-" & (ActiveCell.Offset(0, -2).Address(False, False)) & "+" & (ActiveCell.Offset(0, -1).Address(False, False))
    Selection.Copy
    Range(Selection, "J3").Select
    ActiveSheet.Paste

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    In R1C1 notation:
    R3C2 is the absolute reference to Row 3 Column 3, a.k.a. $B$3

    R[3]C[2] is the relative referece to the row 3 columns to the right and three columns down. when put in A1, R[3]C[2] refers to D3

    Mixed forms

    R1C[2] is the cell in row 1, two columns to the right

    RC2 is shorthand for R[0]C2, the cell in Column 2 of the same row.

    So to put =$K$3 in any cell
    ActiveCell.FormulaR1C1 = "=R3C11"
    Does that help.
    Last edited by mikerickson; 12-20-2007 at 10:21 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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