+ Reply to Thread
Results 1 to 2 of 2

FormulaR1C1 = "VLOOKUP()" with VARIABLE RANGE

  1. #1
    Registered User
    Join Date
    06-05-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    1

    FormulaR1C1 = "VLOOKUP()" with VARIABLE RANGE

    Hello,

    I'm trying to create a macro that puts a vlookup formula into a column of cells. So far this is what I have:

    Sub Test_Earns_Rev_VLookup_2()

    Sheets("Earnings Revision Data").Select
    For i = 1 To 2
    Worksheets("Earnings Revision Data").Cells(2 + i, 3).Select
    beg = i * 10
    ends = i * 10 + 9

    ActiveCell.Formula = "=VLOOKUP(RC[-1],'Beg. Yr. Estimates'!B" & beg & ":D" & ends & ",2,TRUE)"

    Next i
    End Sub

    The output I get for just these two iterations is:

    =VLOOKUP(B3,'Beg. Yr. Estimates'!'B10':'D19',2,TRUE)
    =VLOOKUP(B4,'Beg. Yr. Estimates'!'B20':'D29',2,TRUE)

    Which is SO CLOSE to what I need. EXCEPT for the ' ' around the cells in the range. The strange thing is that if I remove the = from the sub (ActiveCell.Formula = "VLOOKUP(RC[-1],'Beg. Yr. Estimates'!B" & beg & ":D" & ends & ",2,TRUE)" ) the range goes in perfectly with no ' '. But then it's not a formula so, of course, isn't helpful.

    Any help with this would be very much appreciated!

  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: FormulaR1C1 = "VLOOKUP()" with VARIABLE RANGE

    You can't mix R1C1 and A1 references like that -- they have to be one or the other.

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

+ 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