+ Reply to Thread
Results 1 to 14 of 14

select from a range if maximum exceeded

  1. #1
    Registered User
    Join Date
    09-23-2008
    Location
    Dallas, TX
    Posts
    7

    Question select from a range if maximum exceeded

    I hope the title makes sense. I have a spreadsheet that I'm trying to use to calculate volumes of liquid. For each liquid there is a minimum and maximum amount that can be included in a vial, and a checkbox to indicate if it should be included or not. What I'm having trouble with is some logic (other than a million if= statements) to determine the amount of each needed.

    If only a few are selected, using the max value for each is fine as it is below the volume of the vial, so I want to use the max. But if enough are selected, the max for each would exceed the volume of the vial, and I want to pick a percentage of each component's range until we get a volume that will fit in the vial (ie, it figures out that 84% of the max for each will fit, but knows never to drop below the min).

    If possible I would greatly prefer to not use VBA to do this.

    Thanks for your thoughts,
    -Rob
    Last edited by DoctorMac; 09-23-2008 at 12:29 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    It might help if you posted a sample spreadsheet showing what you are working with.... and what results you might expect.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    09-23-2008
    Location
    Dallas, TX
    Posts
    7
    Here is a basic example. The real sheet is much larger, and the min and max volumes are calculated and not manually entered, but that shouldn't matter. The vial # can be 1-4, but I think if it can be done for one vial I can figure out how to apply it to all.

    In this example all the substances set to be included in vial 1 would be more than the 5mL limit of the vial if I set each to the max. I need it to tell me to use a volume that is about 88% of the max (to the nearest 0.1) to get under 5mL. But if I set the vial size to 1mL it should tell me that it cannot be done.

    The only thing that has sprung to mind is to calculate the percent needed by B10/SUMIF(D3:D8,1,C3:C8) and then use that # x the max value in column C. But that does not address the lower limit issue.

    Thanks,
    -Rob
    Attached Files Attached Files

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Does this formula in E3, copied down do it?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-23-2008
    Location
    Dallas, TX
    Posts
    7
    Not exactly, that returned a value of 2 for E8 and it should be zero as it is not in a vial. Amazing how just figuring out what your question really is helps you solve it. I think I'm getting close. Here is what I have in E3 right now, but I still need some way to keep it from dropping below the min (and telling me that it's not possible).
    Please Login or Register  to view this content.
    Maybe I could nest another IF statement to say if the result of that formula is < row B to return an error message?

    The other problem is that if you really increase the max, say change C4 to =8, it drives down the other substances, instead of hitting their lower limit and just using a lesser percentage of substance B.

    EDIT: I see now that your suggestion has a way to account for the total being >B10, which mine lacks. But the problem of a very high max still applies.

    -Rob
    Last edited by DoctorMac; 09-23-2008 at 01:38 PM.

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    If you are only interested in Vial #1, then...

    Please Login or Register  to view this content.
    copied down.

    If you enter 1 in B10, you will get the error message...

  7. #7
    Registered User
    Join Date
    09-23-2008
    Location
    Dallas, TX
    Posts
    7
    That gives me 1.9 in E4 and E5, it should be 1.7.

    -Rob

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Are you sure? I get 1.7 in both those cells.

    See attached.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    09-23-2008
    Location
    Dallas, TX
    Posts
    7
    Weird. I did, but I've fiddled with so many things in that example that it's very possible that I messed something else up.

    I decided that before I made everything pretty, I should work it out "longhand" if you will. As such this has more cells than needed, but lets me see what I'm trying to do. It almost works, but if you change the vial size to 4 it puts too much in. It avoids dropping below the minimums though. I just need to figure out some logic to keep it from exceeding the total, and then to comrpess things in to fewer cells.

    -Rob
    Attached Files Attached Files

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Probably, it is best you keep it the way you have it...and just hide the "helper" columns....

    This way, you are not repeating the same functions in the formula...

  11. #11
    Registered User
    Join Date
    09-23-2008
    Location
    Dallas, TX
    Posts
    7
    Yeah, for starters hiding columns is surely better.

    The problem is that I still can't figure out what to do to knock down the high values that make things exceed the vial volume. Everything I think of leads to circular logic patterns.

    -Rob

  12. #12
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Would it be as easy as using the MIN() function?

    E.g. in E3: =MIN(C3,IF(D3=0,0,IF(G3>H3,G3,H3))) copied down

  13. #13
    Registered User
    Join Date
    09-23-2008
    Location
    Dallas, TX
    Posts
    7
    That is a slightly more elegant way of selecting the low value. But it still leads to allowing for too much in the vial. Somehow the individual values in E need to look at the total in E10 and if it's > B10 decrease themselves if possible. If it's not possible, then we need to return an error message.

    -Rob

  14. #14
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    How about if you move the formula you currently have in column E to a new "helper" column, say column I... and sum those at the bottom...

    Then in E3, use =IF($I$10>$B$10,"Below Min",I3) copied down... that would eliminate circular referencing

+ 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. Select Case Statement
    By Gos-C in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-13-2008, 09:34 AM
  2. Range Select!
    By DMA in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2008, 02:52 AM
  3. select a range
    By divingdingo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2007, 07:50 AM
  4. <Resolved> Select range
    By Roshan10043 in forum Excel General
    Replies: 2
    Last Post: 10-25-2007, 02:38 AM
  5. Getting range of cells with specific text colour, then using in a COUNTIF formulae
    By cheekyflash in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2006, 08:58 PM

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