+ Reply to Thread
Results 1 to 19 of 19

Shift all values in a range until ≤ range of values in array table

  1. #1
    Forum Contributor
    Join Date
    11-15-2011
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    163

    Shift all values in a range until ≤ range of values in array table

    Hi All,

    I am wondering how I can input a range of values in a sheet and use formula to calculate what range of values within an array that the input values are all less than or equal to.

    Edit - I have attached a WS as example. Row 4 should contain the formula the works out what range my inputs values are less than or equal too. In this example Range 8 is the answer.

    Please note I am only looking for the closest range of values that my input range is less than or equal to.

    Hope this make sense.
    Attached Files Attached Files
    Last edited by rtcwlomax; 07-24-2015 at 01:31 PM.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,427

    Re: Shift all values in a range until ≤ range of values in array table

    You can use:

    =MAX(range)

    As this will give you the maximum value of that range, then all cells will be less than or equal to it.

    Hope this helps.

    Pete

  3. #3
    Forum Contributor
    Join Date
    11-15-2011
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    163

    Re: Shift all values in a range until ≤ range of values in array table

    Hi Pete,

    Thanks for reply. MAX function returns the maximum value in a range. It does not do a comparison of one value against another range of values.

    I'm starting to think I might need to do a vlookup of some sort. Can you combine vlookup with IF statements?
    Last edited by rtcwlomax; 07-24-2015 at 01:28 PM.

  4. #4
    Forum Contributor
    Join Date
    11-15-2011
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    163

    Re: Shift all values in a range until ≤ range of values in array table

    Been trying Vlookup(target,range,match, -1) but not sure how to get it working. Any ideas?

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,427

    Re: Shift all values in a range until ≤ range of values in array table

    It's not a good idea to edit a post after someone has replied to it - it is not always noticeable that the post has been changed.

    Having downloaded your file, I haven't a clue what you are trying to achieve.

    Pete

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Shift all values in a range until ≤ range of values in array table

    I believe you would need to use the Solver for this one. You want to minimize the difference between input and range for each value and thereby getting the optimum range. I don't use the solver often, I'll see what I can do. SHG is good with Solver.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Shift all values in a range until ≤ range of values in array table

    Okay, I added cell L3 where I put a 1 and Cell K5 where I put the formula
    =SUM(C5:J5)
    Then in B4 copied to the right
    =INDEX(B$8:B$19,L3)
    The Solver Add on needs to be enabled. Then you will find SOLVER on the Data Tab

    Set Objective K5 to Min
    Add Contraints
    L3<=8
    L3 = Integer
    L3 >=1
    Select a Solving Method : Evolutionary
    Options> Evolutionary Tab Max Time without Improvement 2

    Then "Solve"
    See Attachment
    Attached Files Attached Files

  8. #8
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Shift all values in a range until ≤ range of values in array table

    Since you only have 12 ranges, here's a non-Solver Approach
    In K8 copied down
    =ABS(SUMPRODUCT(C8:J8-$C$3:$J$3))

    Then in B4 copied right
    =INDEX(B$8:B$19,MATCH(MIN($K$8:$K$19),$K$8:$K$19,0))
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    11-15-2011
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    163

    Re: Shift all values in a range until ≤ range of values in array table

    Quote Originally Posted by Pete_UK View Post
    It's not a good idea to edit a post after someone has replied to it - it is not always noticeable that the post has been changed.

    Having downloaded your file, I haven't a clue what you are trying to achieve.

    Pete
    Apologies, I hit enter on my original post before I had finished and didn't see you reply until after that.

  10. #10
    Forum Contributor
    Join Date
    11-15-2011
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    163

    Re: Shift all values in a range until ≤ range of values in array table

    Quote Originally Posted by ChemistB View Post
    Since you only have 12 ranges, here's a non-Solver Approach
    In K8 copied down
    =ABS(SUMPRODUCT(C8:J8-$C$3:$J$3))

    Then in B4 copied right
    =INDEX(B$8:B$19,MATCH(MIN($K$8:$K$19),$K$8:$K$19,0))
    Hi ChemistB,

    Thank for your input and I see where you are coming from but unfortunately it does not work correctly.

    If you input these values you will see that Val-1 Input exceeds the Val-1 in Range 6.

    66 56 50 44 41 39 37 33

  11. #11
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Shift all values in a range until ≤ range of values in array table

    So in your first set of numbers
    70 64 58 52 51 47 45 41
    starting at range 7, Val #8 is is greater than the input so shouldn't the result for the first set be Range 6?
    Last edited by ChemistB; 07-24-2015 at 04:36 PM.

  12. #12
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Shift all values in a range until ≤ range of values in array table

    If I'm right then this in Column K copied down

    =(SUMPRODUCT(--(C8:J8>=$C$3:$J$3)))
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    11-15-2011
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    163

    Re: Shift all values in a range until ≤ range of values in array table

    Apologies, I dont think I have explained it correctly and what I am trying to achieve.

    I have attached a WB with conditional formatting which highlights all cells where the Input value in each column is <= corresponding values in each Range X column.

    In the workbook Range 8 is the first range where all values in the input range are <= Range X values
    Attached Files Attached Files

  14. #14
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,427

    Re: Shift all values in a range until ≤ range of values in array table

    Put this in K9:

    =SUMPRODUCT(--(C9:J9<=C$3:J$3))

    and copy down to K20. Put this array* formula in K22:

    =MIN(IF(K9:K20=0,ROW(K9:K20)-8))

    *An array formula needs to be committed using the key combination Ctrl-Shift-Enter (CSE) instead of the usual <Enter>.

    Then you can have this formula in B4:

    =INDEX(B$9:B$20,$K$22)

    which can be copied across to J4.

    Hope this helps.

    Pete

  15. #15
    Forum Contributor
    Join Date
    11-15-2011
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    163

    Re: Shift all values in a range until ≤ range of values in array table

    Thanks for reply. I have entered formulas in sheet but it returns the incorrect Range. In the attached sheet all the input values are <= Range 8 values in each individual column however the formula returns Range 9 as answer.

    I have added a TRUE FALSE table to the sheet and added SUMPRODUCT to COL K. I now need the formula in B37 that looks up the first 1 value in Col K and returns Range X value.

    I can then use Vlookup to fill in the rest of the values in C37:J37 from Table 1.

    Any help appreciated.
    Attached Files Attached Files
    Last edited by rtcwlomax; 07-25-2015 at 06:52 AM.

  16. #16
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,427

    Re: Shift all values in a range until ≤ range of values in array table

    Change the formula in K9 to this:

    =SUMPRODUCT(--(C9:J9<C$3:J$3))

    (i.e. get rid of the = sign), then copy down to K20.

    Hope this helps.

    Pete

    EDIT: you will also have to change the array* formula in K37 to this:

    =MIN(IF(K25:K36=1,ROW(K25:K36)-24))

    if you want the lower table to show the correct result.

    * commit using CSE, as advised previously.

    Pete
    Last edited by Pete_UK; 07-25-2015 at 07:58 AM.

  17. #17
    Forum Contributor
    Join Date
    11-15-2011
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    163

    Re: Shift all values in a range until ≤ range of values in array table

    Thanks Pete,

    Yes, that works nicely.

  18. #18
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,427

    Re: Shift all values in a range until ≤ range of values in array table

    And here's the file that I tested it out on last night, before my post #14.

    Hope this helps.

    Pete
    Attached Files Attached Files

  19. #19
    Forum Contributor
    Join Date
    11-15-2011
    Location
    UK
    MS-Off Ver
    Excel 2013
    Posts
    163

    Re: Shift all values in a range until ≤ range of values in array table

    Thanks again Pete,

    I dont want to push it, but is there any way its possible to do away with Col K and just use formula if cells C4:J4 to get the same result?

    I'm guessing would probably need to use a VBA loop?

+ 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. Add values from range to array??
    By vepoyoke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2014, 12:33 PM
  2. put the values of an array into a range
    By HarryKlein in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2014, 09:33 AM
  3. Select a range, remove 0 values returned from formula, shift all others left
    By Gabby11 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-31-2013, 11:33 AM
  4. Getting Range values into an array
    By juancomco in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2013, 04:27 PM
  5. Replies: 0
    Last Post: 02-22-2011, 01:56 PM
  6. range values in an array?
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-16-2005, 01:00 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