+ Reply to Thread
Results 1 to 10 of 10

script to go through a list and select the lowest price at specific locations

  1. #1
    Registered User
    Join Date
    11-07-2013
    Location
    Sverige
    MS-Off Ver
    Excel 2013
    Posts
    6

    script to go through a list and select the lowest price at specific locations

    Hello all!

    I have very limited experience with programming. But i need to write a function for my spreadsheet. Let me try to explain.

    In the spreadsheet there are several lists. Each list contain the price and location of one commodity. In column A there is a description of the location, and in column B the price is listed. Each list is sorted by price (low to high). For some commodities there are up to 50 locations and for some only a few. Since it's sorted by price, the same location can appear randomly through out the list if there are more then one supplier on that specific location.

    Here's what i need to do. I'm only interested in 5 specific locations, and i'm only interested in the lowest price of each location. Since there is over 50 lists, and they are updated frequently, i can't go through all information manually. Let's call the locations "L1 - L2 - L3 - L4 - L5".

    First of all, i have all the lists on one sheet and i want the function to go through the lists and get the lowest prices from each location, for each commodity, and put them on a separate sheet where i have it organised so i can get a good overview of the information.

    So here is what i'm thinking in (what i think is) pseudo code.

    ___________________________________________________________________________________________

    Start from the top of the Column A (location) of the first list

    * Start loop

    * * If (the cell contains the name of L1)

    * * * Copy the price from the same line but column B (price) and paste it on a specified cell in the overview sheet.

    * * * End loop


    * * else if (the cell does not contain the name of L1)

    * * * Step down one cell and repeat


    * * else if (The cell contain no text) ;;;there was no match

    * * * Stop searching for L1

    * * * End loop


    * Start loop

    * * If (the cell contains the name of L2)

    * * * Copy the price from the same line but column B (price) and paste it on a specified cell in the overview sheet.

    * * * End loop


    * * else if (the cell does not contain the name of L2)

    * * * Step down one cell and repeat


    * * else if (The cell contain no text) ;;;there was no match

    * * * End loop
    _____________________________________________________________________________


    And so on for each of the 5 locations. I'm guessing it's not optimal - but it seems to be the most intuitive approach for someone with limited experience like me. When it's finished with one list i want it to move on to the next. But maybe if i can get going with this i will be able to figure that out by my self!!

    Any help would be greatly appreciated!


    Best Regards,
    milmil
    Last edited by milmil; 11-07-2013 at 03:16 PM.

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: script to go through a list and select the lowest price at specific locations

    It seems a formula could be a good beginning.
    Can you send a short sample file to test

  3. #3
    Registered User
    Join Date
    11-07-2013
    Location
    Sverige
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: script to go through a list and select the lowest price at specific locations

    Hi,

    I don't have it in front of me right now. But i made a simple mock-up. It's attached.


    Thank you for replying!
    Attached Files Attached Files

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: script to go through a list and select the lowest price at specific locations

    Hi and welcome to the forum

    Try this ARRAY formula, copied down...
    =MIN(IF($E$5:$E$30=B5,$F$5:$F$30))
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Registered User
    Join Date
    11-07-2013
    Location
    Sverige
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: script to go through a list and select the lowest price at specific locations

    I actually managed to solve it my self. But i'm posting it here in case anyone got any general advice on how to make it better. And for future reference if some one like me needs help with a similar problem.

    Please Login or Register  to view this content.

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: script to go through a list and select the lowest price at specific locations

    Good job on the macro Did you see my suggestion in post # 4?

  7. #7
    Registered User
    Join Date
    11-07-2013
    Location
    Sverige
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: script to go through a list and select the lowest price at specific locations

    oh, i didn't notice your post, sorry!

    It seems like an easy solution (those are generally the best). But i can't quite get it to work, despite using ctrl+shift+enter. And i have to admit that i'm not familiar with that kind of formula at all so i have no idea what i should expect or what i'm doing wrong.

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: script to go through a list and select the lowest price at specific locations

    take a look at the attached...
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-07-2013
    Location
    Sverige
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: script to go through a list and select the lowest price at specific locations

    ah, now i see the problem! my Swedish version of excel couldn't handle formulas in English (the "IF" part). But now that i downloaded it from you, it got translated automatically. Kinda silly that all the formulas in excel are translated between versions when VBA isn't.

    And thanks a lot! It's a great solution because with this i wont have to run the macro every time the lists get updated. Very much appreciated!

    And btw, what kind of formula is this and where can i learn more about them?

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: script to go through a list and select the lowest price at specific locations

    Its what's called an ARRAY forumla, here are just 2 sites that explain it far better than I could...
    http://office.microsoft.com/en-us/ex...001087290.aspx
    http://www.cpearson.com/excel/ArrayFormulas.aspx

    I googled excel array formulas and got 1/2 a mil hits

+ 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. [SOLVED] Lowest price & Lowest lead time
    By thup_98 in forum Excel - New Users/Basics
    Replies: 11
    Last Post: 01-22-2013, 03:21 PM
  2. [SOLVED] Lookup lowest value in a list for an item for a specific date
    By JungleJme in forum Excel General
    Replies: 5
    Last Post: 07-26-2012, 05:28 AM
  3. Excel 2007 : Help finding lowest price in list of orders
    By Snoozeburger in forum Excel General
    Replies: 6
    Last Post: 10-14-2010, 03:05 AM
  4. script for writing excel values into specific locations in a text
    By whiz999 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2009, 11:35 AM
  5. Mark the Lowest price in a price-matrix
    By raed_237 in forum Excel General
    Replies: 8
    Last Post: 04-07-2009, 01:24 AM

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