+ Reply to Thread
Results 1 to 5 of 5

How to apply vlookup formula in vba

Hybrid View

  1. #1
    Registered User
    Join Date
    04-29-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    17

    How to apply vlookup formula in vba

    Hi,


    How to apply lookup formula of below in vba

    =LOOKUP(L2, {1,2,5,10,30,1000}, {"1-2 days","2-5 days","5-10 days","10-30 days","30 days+"})


    Thanks in Advance,
    Menaka B
    Last edited by Menaka; 05-01-2013 at 08:55 AM.

  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
    48,945

    Re: How to apply vlookup formula in vba

    One way:

    Dim vResult
    vResult = Application.Evaluate("=LOOKUP(L2, {1, 2, 5, 10, 30, 1000}, {""1-2 days"", ""2-5 days"", ""5-10 days"", ""10-30 days"", ""30 days+""})")

    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
    04-29-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: How to apply vlookup formula in vba

    Hi,

    Thanks for ur reply, but its not applying properly, all columns

    I want something like this to apply for whole "L" Column

    .Range("Z2:Z" & lRow) = Application.Evaluate("=LOOKUP(.Range("$L$2:$L" & lRow), {1, 2, 5, 10, 30, 1000}, {""1-2 days"", ""2-5 days"", ""5-10 days"", ""10-30 days"", ""30 days+""})")



    I've attached the sheet and the VBAcode with this, please take a look at it. The expected result of Z column is in sheet2, column D
    Attached Files Attached Files

  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
    48,945

    Re: How to apply vlookup formula in vba

    OK, do it this way:

    Sub Test()
    Dim wb1 As Workbook
    Dim ws1 As Worksheet
    Dim lRow As Long
    
    Set wb1 = ThisWorkbook
    Set ws1 = wb1.Worksheets("Sheet1")
    
    With ws1
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row
        With .Range("Z2:Z" & lRow)
           .Formula = "=LOOKUP($L2, {1, 2, 5, 10, 30, 1000}, {""1-2 days"", ""2-5 days"", ""5-10 days"", ""10-30 days"", ""30 days+""})"
           .Value = .Value
        End With
    End With
    
    End Sub

    Regards, TMS

  5. #5
    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
    48,945

    Re: How to apply vlookup formula in vba

    Thanks for the rep

+ 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