+ Reply to Thread
Results 1 to 6 of 6

Macro to search cell for a name from a list, then use 1 of 2 formulas to calculate

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Macro to search cell for a name from a list, then use 1 of 2 formulas to calculate

    Hello, let me start off by saying that I am relatively new to VBA and macros in excel. My problem is this, I have a list of suppliers and shipping information, and I need to calculate if their shipments are on time using one of these two macros I've made;

    =IF(U2>14,"Early",IF(U2<-7,"Late","On-Time"))
    =IF(U3>7,"Early",IF(U3<0, "Late", "On-Time"))

    The first macro is for our international suppliers, they are allowed up to 14 days early and 7 days late to count as the shipment being on time, and for suppliers in the states it is 7 days early allowed and 0 days late. What I need to figure out in a macro or VBA is to have it searched the field that contains the supplier name, and if it returns being 1 of the 5 international suppliers (I would have a list of the 5 int. suppliers in the macro somewhere) it would use the first equation to calculate it being on time or not.

    I have attached a sample spreadsheet below, the supplier names in column B are examples of either US suppliers (US1, US2 ect.) or INT1-INT5 for the international suppliers. The blank spacing in between all the columns will be filled in later with other information and can be ignored. The "Status" Column is the field that uses either one of the above macros, and it references the column "Days Early / Late (-)" which is calculated from the "Planned Delivery date"-"Receipt Date"(date we receive the shipment).

    If anyone may have any ideas on how I can be able to do this I would be very thankful.
    Attached Files Attached Files
    Last edited by Hobalong; 05-20-2013 at 11:04 AM. Reason: edited to change to solved

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to search cell for a name from a list, then use 1 of 2 formulas to calculate

    If your supplier name in column B is going to be exactly (US1, US2, etc) and (INT1 - INT5) as indicated then this should work for you:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to search cell for a name from a list, then use 1 of 2 formulas to calculate

    As stnkynts says, because you autfill the formula down the table, then you need to include the if statement to see if the supplier is international or not in the function that you paste down the table. Assuming that your supplier names are not US1, US2, INT1, INT2 etc. then I would suggest using a lookup table to do this, have a table with the supplier names in one column and INT or US in the next column. Then use the Vlookup function to determine which type the supplier is.

    If you want to include it in the macro, you would need to have a for loop to populate the table and then put an if statement in the macro.

  4. #4
    Registered User
    Join Date
    05-17-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to search cell for a name from a list, then use 1 of 2 formulas to calculate

    Sorry miss communication on my part, the names I gave above were just examples. Would I make a If statement similar to yours but for the five international suppliers I include their names? The five international supplier names are "DONGGUAN QINGXI LIAN", "WINTAGE ENGINEERS &", "GNOTEC MEFA AB", "PT TEXMACO PERKASA", and "IMPERIAL AUTO INDUST". How would I go about making an IF then else for these five names, and if it doesn't return being those 5 international sup. that it uses the second formula?

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to search cell for a name from a list, then use 1 of 2 formulas to calculate

    Either make a lookup table as suggested or type it longhand into the formula but it becomes a bit unreadable:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-17-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to search cell for a name from a list, then use 1 of 2 formulas to calculate

    Thank you both, I was able to solve my problem.

+ 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