+ Reply to Thread
Results 1 to 9 of 9

For loop vlookup

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: For loop vlookup

    Thanks ragulduy. I get a #N/A error but that's probably because I've set up my ranges/counter wrong. What I would like to do is vlookup Sheet1!A1:A5 (I've changed SrcRange to A1:B5) with Sheet2!A1:B5 and put the values in Sheet1!B1:B5. As I've set it up, I'm doing a vlookup of the counter itself ?

    Dim SrcRange As Range
    Dim LkRange As Range
    Dim x As Long
    
    
    Set SrcRange = Sheets(1).Range("A1:B5")
    Set LkRange = Sheets(2).Range("A1:B5")
    
    For x = 1 To SrcRange.Cells.Count
        SrcRange.Cells(x).Formula = "=VLOOKUP(" & x & "," & LkRange.address & ",2,0)"
    Next

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: For loop vlookup

    I think you would need dollar signs when you set your range.

    Set LkRange = Sheets(2).Range("$A$1:$B$5")

+ 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. Vlookup loop vba
    By mzang7 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-12-2012, 03:13 PM
  2. VBA for Do Until Loop with VLookUp
    By jack.d in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-21-2012, 02:00 AM
  3. VlookUp with Loop?
    By ezek in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-05-2012, 06:24 AM
  4. Replies: 5
    Last Post: 07-29-2009, 07:53 AM
  5. Vlookup loop
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-25-2008, 08:53 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