+ Reply to Thread
Results 1 to 7 of 7

VBA for looping VLookup to last row with data

  1. #1
    Registered User
    Join Date
    09-12-2012
    Location
    DC
    MS-Off Ver
    Excel 2007
    Posts
    24

    VBA for looping VLookup to last row with data

    In the attached workbook in column B (sheet "Upgrade Info") is a list of serial numbers in this format 326ABS3472. On the sheet "APC" is a range of APC Codes and corresponding short descriptions. The APC code is made up of the first three characters of the serial numbers in column B (sheet "Upgrade Info").

    What I am trying to do is look at the first three characters in column B (sheet "Upgrade Info"), match that with the short description on the APC sheet, and return the value to column E of the Upgrade Info sheet. I will not know how many rows the sheet will have so it needs to loop to the last row containing data. The first row containing data will always be row 15.
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,669

    Re: VBA for looping VLookup to last row with data

    =IFERROR(VLOOKUP(LEFT(B15,3),APC!$A:$B,2,FALSE),"")


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-12-2012
    Location
    DC
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: VBA for looping VLookup to last row with data

    I assume I was to post the above formula in column E? That did not work. I was looking to do this in VBA if possible.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,669

    Re: VBA for looping VLookup to last row with data

    Try:

    =IFERROR(VLOOKUP(--LEFT(B15,3),APC!$A:$B,2,FALSE),"")

    Just to see if the formula works. The VBA's not difficult.


    Regards, TMS

  5. #5
    Registered User
    Join Date
    09-12-2012
    Location
    DC
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: VBA for looping VLookup to last row with data

    That formula worked perfectly.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,669

    Re: VBA for looping VLookup to last row with data

    Thanks for the rep.

    Here's the code:

    Please Login or Register  to view this content.

    Regards, TMS


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  7. #7
    Registered User
    Join Date
    09-12-2012
    Location
    DC
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: VBA for looping VLookup to last row with data

    Thanks for the incredibly fast response. Worked great!

+ 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