+ Reply to Thread
Results 1 to 7 of 7

VBA Code, VLookUp, Loop

  1. #1
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    VBA Code, VLookUp, Loop

    I have 2 sheet in my workbook, sheet1 is the look up table and sheet2 is where you key the item number to display the result. Right now, I have a formula written on it but every time I add a line item I have to copy the formula and it is running slow. I want to convert it into a VBA code so that only the value is stored on a line item. I need help on writing a VBA code.

    Here are the details:
    Sheet1 (Look up table)
    Row 3 is the Heading
    A4, Item No.
    B4, Location
    C4, On Hand
    D4, Status
    E4, Description

    Sheet2 (Result of lookup table)
    Row 4 is the heading
    A5:E5, this is where you type an info
    F5, this is where you type the Item No. for lookup
    G5, this is where the result of the DESCRIPTION lookup from sheet1
    H5:N5, this is where you type an info
    O5, this is where the result of the STATUS lookup from sheet1
    P5, formula to combine C5+D5 (text value)

    Then, advance to the next Row (loop)

    Thank you in advance for your help.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Code, VLookUp, Loop

    Well, unless you are going to have an event driven code, you still need to run the code if you want to update it. It is the same with formula.

  3. #3
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: VBA Code, VLookUp, Loop

    Thanks for your reply...

    Yes, there will be a function to update it, like SHIFT+CTRL+U or any suggestion from your end. I just don't know how to write the code and maybe you can help me.

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

    Re: VBA Code, VLookUp, Loop

    Can you attach a workbook with some sample data?

    To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

  5. #5
    Forum Contributor
    Join Date
    08-14-2013
    Location
    Florida
    MS-Off Ver
    Excel 2013
    Posts
    105

    Re: VBA Code, VLookUp, Loop

    Try this... This assumes Sheet1 is named Sheet1 and Sheet2 is Sheet2. Set this to Worksheet 2, Change, in VBA.
    Anytime someone enters an item number in Column 6, the Item number will do Vlookup from Sheet1 for Description and Status. Then C5 and D5 get combined. Then all formulas get changed to values.



    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: VBA Code, VLookUp, Loop

    Thanks Kalithro,

    Got and tested your code and it works fine, however, I have few modifications:
    1. Sheet1 should be named “DATA”
    2. Sheet2 should be named “TRANS”
    3. P5, formula to combine “J+K+L+M” (text value) with a dash (“-“) in between
    4. The sheet is locked and some cells are locked
    5. Sequence of entry is from Column A to P
    • A:E- Type info (cell is unlock)
    • F – Item No. entry (cell is unlock)
    (when you type ITEM NO. , J,K,L,M is still blank, so what will trigger when you enter data on row J,K,L,M to combine it?)
    • G – Description (result from Vlookup) (cell is locked)
    • H:N – Type info (cell is unlock)
    • O – Status (result fromVlookup) (cell is locked)
    • P- text result by combining J+K+L+M (cell is locked)

    Also, I tried for 5,000 line items and it becomes slow because it calculates every time you enter a new line.

    Thank you again and hope to received your revised code.

    Kudos to you guys for sharing your talents for those in need...

  7. #7
    Forum Contributor
    Join Date
    12-01-2012
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: VBA Code, VLookUp, Loop

    Hello guys, I need help on the revision of VBA code above. Any help would be appreciated. Thanks

+ 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. Loop the code
    By mayurpatil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2013, 04:05 PM
  2. Code to turn this code into a loop doing muliple copies
    By fbplaya02 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2013, 12:02 PM
  3. Excel 2007 : VBA Loop Code --- Help me :-)
    By EggHead in forum Excel General
    Replies: 2
    Last Post: 12-14-2009, 03:20 PM
  4. Replies: 5
    Last Post: 07-29-2009, 07:53 AM
  5. How To Loop with below code
    By pr4t3ek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-10-2008, 09:39 AM

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