Closed Thread
Results 1 to 2 of 2

VBA - Lookup with multiple conditions/criteria

  1. #1
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    VBA - Lookup with multiple conditions/criteria

    I'm sorry to put it here...but I've posted under VBA section, and didn't get any result. That's why I'm posting it here and hope that there'll be experts who could help me out.

    If I can avoid macro...I'll definitely avoid it completely!!! However, I have to do this in macro, reason being, my manager wants it to. As well, I tried to have condensed a formula, but excel won't take it, probably it's too long.

    Anyway, I've attached a sample of it...wb1 and wb2.

    wb1 is how part of the actual data is...and it contains all the "criteria" that I need to look at. Column G (currency) and column H (rate) is how it would have been with the formula.

    How I get the currency:
    1st. Look at column F (in this case, there's only 1 partner code id) - partner code id is AUSOP
    2nd. Look at column B and determine the "earliest" and "latest" date. In our data, 201012 is earliest date and 201208 is the latest date in column B.
    3rd. With the above 2 criterias, it's time that we look at wb2.
    4th. In wb2, 'Partner Rates' sheet, noticed that we have 2 AUSOP partner code in column A (colored in yellow). But the effective date and end date of these 2 are different. With the vlookup array formula, it has taken row 4 (colored green) since our earliest date in wb1 (201012) is <= effective date in wb2 of row 4, the same with our latest date in wb1 (201208) >= end date in wb2.
    5th. Since there's a match, we take column F.

    How I get the Rate:
    1st. The step is the same as above where the code has to determine which row to take after meeting the criteria (partner code, earliest date <= effective date, and latest date>= end date)
    2nd. on wb1 at column C, we determine if it's a "GPRS, SMS or Voice".
    3rd. If it's GPRS, we return the rate (column O of wb2) in the determined row on wb2 (in our example, row 4).
    4th. If it's SMS, we return the rate (column N of wb2) in the determined row on wb2 (in our example, row 4).

    5th. Voice would be a little troublesome, since it has to look at the country (column E) in wb1, then look up at wb2 "Special Destination" Sheet to determine if it's 'YES' and then return the rate value (column J of wb2 "Partner Rates" sheet). At this point, I'll ignore this for a while and try to do it myself.

    PS: wb2 has named ranged.

    Below is part of the code where I try to do a multiple search criteria...but just don't know how to.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA - Lookup with multiple conditions/criteria

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread. http://www.excelforum.com/excel-prog...-criteria.html

    Thread Closed.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed 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