+ Reply to Thread
Results 1 to 7 of 7

Loop function with vlookup

  1. #1
    Registered User
    Join Date
    08-10-2007
    Posts
    34

    Loop function with vlookup

    Hey all, i'm back!

    Starting my second internship with the same company. I've got a question for everyone, How can I make a loop function in VBA work with a vlookup function. This is the best i've done, but no such luck.

    Sub Vlookup()

    ' This Macro runs as long as there is something in the previous column
    Do While IsEmpty(ActiveCell.Offset(0, -6)) = False
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R4C3,'Current Data'!A:B,2,FALSE)"
    ActiveCell.Offset(1, 0).Select
    Loop
    End Sub

    Obviously, what I am trying to do here is use a vlookup function in column G starting at row 4. For now, I'm OK with having to click on that cell before I run the macro, but assigning it a value would be nice . The vlookup function should run down the sheet, moving the lookupvalue down one row as the formula moves down. It should end when there is no value in column A.

    I have two problems.
    1 - The function returns a #name? value, even tho if the forumla is just entered, it works fine.
    2 - I'm not sure how to make the vlookup value target cell go down one row each time as well.


    Any input to send me on the correct path would be wonderful.


    Thanks in advance.

    `Ryan

  2. #2
    Registered User
    Join Date
    08-10-2007
    Posts
    34

    Maybe an example will help...

    Here is an example workbook.

    If anyone can modify my code to made column D match column F, it would be greatly appreicated.

    Thanks again,

    `Ryan

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Engineers08; 05-30-2008 at 01:25 PM.

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, I'm afraid there no "VLookup" but I think it does what you want:-
    Please Login or Register  to view this content.
    Regards Mick

  4. #4
    Registered User
    Join Date
    08-10-2007
    Posts
    34

    So perfect!

    Thanks a lot!

    I don't mind at all that there is no vlookup, it just appeard to be the easy way to do it.


    Thanks again,

    `Ryan

  5. #5
    Registered User
    Join Date
    08-07-2010
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Loop function with vlookup

    How about vlookup in 2 data (data1 & data2 sheet) and the lookup value will post in Main sheet? whats the code for that?




    Thanks,
    Kooper

  6. #6
    Registered User
    Join Date
    11-28-2011
    Location
    chennai
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Loop function with vlookup

    Dear Mick,

    The below code is great but can you explain each line with comments i tried but i couldn't understand the cl and the ocl one.. the odat and rang is ok but i couldn't understand the rest pls do us a favor so all will come to know.




    Quote Originally Posted by MickG View Post
    Hi, I'm afraid there no "VLookup" but I think it does what you want:-
    Please Login or Register  to view this content.
    Regards Mick

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Loop function with vlookup

    Hello sriram170 & Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    HTH
    Regards, Jeff

+ 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