+ Reply to Thread
Results 1 to 5 of 5

VBA If Vlookup

  1. #1
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague
    MS-Off Ver
    Excel 2013
    Posts
    160

    VBA If Vlookup

    Hi all.

    I need a help with transferring excel function in to VBA code. In column G in sheet "List" I have the below formula.

    VBA If Vlookup.xlsb

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    In this formula, every value in column B in sheet "List" is compared with the range "A2:B26" in "Pickup list" sheet to get the "Type" value.
    e.g.:
    A1 = CB
    A2 = CB
    A3 = AT
    A4 = AT
    A5 = CB
    A8 = WHS
    A9 = WHS

    If it get result "WHS", Its looking in range "E2:H10" in sheet "Pickup list" which value is in the 3rd column if the range if the lookup value is in column "E".
    If it get result "CB", Its looking in range "E2:H10" in sheet "Pickup list" which value is in the 4th column if the range if the lookup value is in column "E".
    If the value in column "E" can not be found in the range "E2:E10" in sheet "Pickup list", then it will use the first lower value.
    If the model in column "B" in sheet "List" is not "CB" or "WHS", then the value should be 0.

    e.g.:

    Type NOPR MAXRESVP
    CB 49 0.37
    WHS 24 0.5
    ZZ 108 0
    CB 104 0.15
    CB 105 0.15
    CB 114 0.15
    WHS 114 0.07
    ZZ 34 0
    CB 47 0.45
    ZZ 22 0



    I wanted to transfer this formula to VBA, but it does not work.

    Please Login or Register  to view this content.
    Can someone help me with this.

    Thank you
    Igor
    Last edited by igormigor; 11-23-2015 at 11:06 AM.

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: VBA If Vlookup

    1 you need to pass your named ranges to VBA
    2 there is no need to use worksheetfunctions here
    3 you will get the best performance of a macro if you do like this: Dim rm(): rm = Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 100))

  3. #3
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague
    MS-Off Ver
    Excel 2013
    Posts
    160

    Re: VBA If Vlookup

    Sorry, but I don't understand where and I need to change. Can you advise how and what I need to change in my code.
    Thank you.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: VBA If Vlookup

    without your file?

  5. #5
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague
    MS-Off Ver
    Excel 2013
    Posts
    160

    Re: VBA If Vlookup

    I've figure out how to do it differently. Maybe not the best way, but it works.

    Please Login or Register  to view this content.
    Thank you for your help on this.

+ 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. Using vLookup based on results from a vLookup & returning an undetermined list
    By NormalityBan in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 08-14-2014, 05:02 AM
  2. Replies: 0
    Last Post: 12-26-2013, 01:12 PM
  3. Display Cell within VLookup range that excel thinks matches the VLookup Value
    By headachexcelperson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-04-2013, 04:56 PM
  4. [SOLVED] Vlookup is not working and giving =vlookup(B2,$T$2:$U$135,2,false) this kind of values.
    By yogeshsharma1981 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-09-2013, 04:08 PM
  5. vlookup? match? index? MULTIPLE criteria for vlookup search problem....
    By aborg88 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-11-2013, 09:56 AM
  6. Replies: 5
    Last Post: 07-29-2009, 07:53 AM
  7. vlookup function-Can vlookup command find the data from the 5 sheets.
    By Rishab shah in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

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