+ Reply to Thread
Results 1 to 3 of 3

Using VBA Variable in R1C1 Formula

  1. #1
    Registered User
    Join Date
    04-20-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Using VBA Variable in R1C1 Formula

    Please help!

    I have this variable in my VBA code:

    Dim lastColumn As Integer
    lastColumn = ActiveSheet.Cells(7, Columns.Count).End(xlToLeft).Column

    I have this formula as well:

    ActiveCell.FormulaR1C1 = _
    "=IF(RC[1]="""",1,IF(AND(RC[1]=1,LEFT(R[2]C,4)=LEFT(R[2]C[1],4)),1,IF(OR(LEFT(R[2]C,4)=LEFT(R7C30,4),R[2]C=VALUE(CONCATENATE(LEFT(R7C30,4)-1,RIGHT(R7C30,2)))),1,0)))"

    Currently, lastColumn = 37 so I need the 30 in the formula to be lastColumn - 7 and to be absolute referenced. This lastColumn number will change each month. Next month it will be 38 and I will want the 30 to be 31, so lastColumn - 7 is what I need. How do I recode this formula so it works? I've tried many things.

    Thanks

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,086

    Re: Using VBA Variable in R1C1 Formula

    It is difficult without sample to do a test, perhaps try:
    NOT TESTED
    lastColumn = lastColumn - ActiveCell.column -7
    ActiveCell.FormulaR1C1 = _
    "=IF(RC[1]="""",1,IF(AND(RC[1]=1,LEFT(R[2]C,4)=LEFT(R[2]C[1],4)),1,IF(OR(LEFT(R[2]C,4)=LEFT(R7C30,4),R[2]C=VALUE(CONCATENATE(LEFT(R7C30,4)-1,RIGHT(R7C" & lastColumn & ",2)))),1,0)))"
    - Battle without fear gives no glory - Just try

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

    Re: Using VBA Variable in R1C1 Formula

    Which cell/column are you putting the formula in?
    If posting code please use code tags, see here.

+ 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. Using R1C1 formula in VBA changes all references from CELL("address") function to R1C1?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-20-2014, 04:17 PM
  2. [SOLVED] Putting variable into R1C1 formula
    By drrazor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2014, 07:27 AM
  3. Vlookup HELP R1C1 variable
    By toutai in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2014, 04:41 AM
  4. How can one use a variable in a VBA formula in R1C1 notation?
    By Frisbeeman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2012, 06:34 PM
  5. formula R1C1 vs variable
    By ilkamalo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2009, 11:25 AM
  6. using a variable in a R1C1 formula
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2007, 05:59 PM
  7. R1C1 format using a variable?
    By jim37055 in forum Excel General
    Replies: 3
    Last Post: 10-04-2005, 12:47 PM

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