Consulting

Results 1 to 5 of 5

Thread: Loop through Vlookup

  1. #1

    Loop through Vlookup

    Gents,

    I believe this is quite simple, but..... not to me :-)

    How can I make the this code, keep checking for new entries from C10 to ?? and make it stop if it comes to an empty cell in "C"

    Sub VlookUp()
    Dim ws1 As Worksheet
    Set ws1 = Sheets("2_COPY_MAST_LIST")
    ws1.Range("O10").Value = WorksheetFunction.VlookUp(ws1.Range("N10").Value, ws1.Range("AA8:AB39"), 2, 0)
    ws1.Range("O11").Value = WorksheetFunction.VlookUp(ws1.Range("N11").Value, ws1.Range("AA8:AB39"), 2, 0)
    ws1.Range("O12").Value = WorksheetFunction.VlookUp(ws1.Range("N12").Value, ws1.Range("AA8:AB39"), 2, 0)
    ws1.Range("O13").Value = WorksheetFunction.VlookUp(ws1.Range("N13").Value, ws1.Range("AA8:AB39"), 2, 0)
    ws1.Range("O14").Value = WorksheetFunction.VlookUp(ws1.Range("N14").Value, ws1.Range("AA8:AB39"), 2, 0)
    ws1.Range("O15").Value = WorksheetFunction.VlookUp(ws1.Range("N15").Value, ws1.Range("AA8:AB39"), 2, 0)
    End Sub
    Last edited by Aussiebear; 12-21-2016 at 06:02 AM. Reason: Addwed code tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sub VlookUp()
    Dim ws1 As Worksheet
    Dim lastrow As Long
    Dim i As Long
    
        Set ws1 = Sheets("2_COPY_MAST_LIST")
    
        With ws1
        
            lastrow = .Cells(Rows.Count, "C").End(xlUp).Row
            .Cells(i + 9, "O").Value = WorksheetFunction.VlookUp(.Cells(i + 9, "N").Value, .Range("AA8:AB39"), 2, 0)
        End With
        
        Set ws1 = Nothing
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Not Working - see att. file

    Hi,

    Sorry mate, but it wont work, can you see why?
    Attached Files Attached Files

  4. #4
    May be
    Sub VlookUp()    Dim ws1 As Worksheet
        Dim lastrow As Long
        Dim i As Long
    
    
        Set ws1 = Sheets("2_COPY_MAST_LIST")
    
    
        With ws1
            lastrow = .Cells(Rows.Count, "C").End(xlUp).Row
            For i = 10 To lastrow
                .Cells(i, "O").Value = WorksheetFunction.VlookUp(.Cells(i, "N").Value, .Range("AA8:AB39"), 2, 0)
            Next i
        End With
    
    
        Set ws1 = Nothing
    End Sub

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,057
    Location
    Quote Originally Posted by Offshoredude View Post
    Hi,

    Sorry mate, but it wont work, can you see why?
    No, can you please explain why? There's no excuse for being lazy, post the reason why you think it doesn't work.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •