+ Reply to Thread
Results 1 to 4 of 4

Vlookup and autofill a dynamic range

Hybrid View

  1. #1
    Registered User
    Join Date
    12-07-2009
    Location
    Fiji
    MS-Off Ver
    Excel 2007
    Posts
    16

    Vlookup and autofill a dynamic range

    I am trying to Vlookup and autofill a dynamic range.
    My codes are as below

    Sub test()
    
    Sheets("Data").Select
    Dim LastRow As Long
    LastRow = Cells.Find(What:="*", _
    SearchDirection:=xlPrevious, _
    SearchOrder:=xlByRows).Row
    Range("B2:B" & LastRow).FormulaR1C1 = "= VLOOKUP(A2,Reference!A:B,2,0)"
    Application.CutCopyMode = False
    End Sub
    the Macro runs but it returns

    PBU ID
    10014 #NAME?

    Range("B2:B" & LastRow).FormulaR1C1 = "= VLOOKUP(A2,Reference!A:B,2,0)"
    Need help here so the macro auto fills coloum B

    Help Please
    Sample attached
    Attached Files Attached Files
    Last edited by ajay1967; 01-19-2012 at 08:04 PM. Reason: Forgot the rules for codes

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Vlookup and autofill a dynamic range

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    With six posts you should know the rules.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Vlookup and autofill a dynamic range

    Your code

    Range("B2:B" & LastRow).FormulaR1C1 = "= VLOOKUP(A2,Reference!A:B,2,0)"
    To be changed as

    Range("B2:B" & LastRow).Formula = "= VLOOKUP(A2,Reference!A:B,2,0)"

  4. #4
    Registered User
    Join Date
    12-07-2009
    Location
    Fiji
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Vlookup and autofill a dynamic range

    kvsrinivasamurthy'

    Thank a lot it worked perfectly
    Appreciate your effort.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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