excel question
 

Subscribe now and choose from over 30 free gifts worth up to £49 - Plus get £25 to spend in our shop

[Closed] excel question

12 Posts
8 Users
0 Reactions
103 Views
 mrmo
Posts: 10709
Free Member
Topic starter
 

I can get this to work through brute force, but it isn't elegant.

I have one box into which a number is entered, i then have a list of values.

The number in the box is basically used to do a price calculation.

This is the problem, the number in the box needs to be rounded up to the closest value in the list

example.

it isn't quite so simple as the list doesn't have a pattern but this should explain it.

list is 100, 125, 150, 175, 200, 225

The value entered in the box is 102, the subsequent calculation needs to treat it as 125.
The value in the box is 134, so it is 150.
etc

Is there a simple way of doing this, or is VBA brute force the way forward?


 
Posted : 13/11/2009 9:21 pm
 rs
Posts: 28
Free Member
 

Huh????


 
Posted : 13/11/2009 9:30 pm
 rs
Posts: 28
Free Member
 

wait i get it now after reading it slowly 💡


 
Posted : 13/11/2009 9:31 pm
Posts: 145
Free Member
 

another cell with =v/hlookup(value,array,2,true) should work right??


 
Posted : 13/11/2009 9:32 pm
 mrmo
Posts: 10709
Free Member
Topic starter
 

vlookup gives the closest value below, or at least it does in my fiddling.


 
Posted : 13/11/2009 9:35 pm
Posts: 6
Full Member
 

Your "answers" are all multiples of 25

To round up, say your basic price is in cell A1 and you want the answer in B1:

=(INT(A1/25)+1)*25

workings:
INT(102)/25 = 4 {returns the integer of 102/25, i.e. 4 instead of 4.08}
4+1 =5{makes sure it always rounds up}
5*25 = 125 {multiplies back up to the price}

Or am I missing something?


 
Posted : 13/11/2009 9:44 pm
 mrmo
Posts: 10709
Free Member
Topic starter
 

the real data isn't all multiples of 25, i just used that in the list.


 
Posted : 13/11/2009 9:49 pm
Posts: 6
Full Member
 

It's the lies I can't stand - dammit!

How many prices do you have?


 
Posted : 13/11/2009 9:58 pm
 mrmo
Posts: 10709
Free Member
Topic starter
 

i don't have the list to hand but around 30 values ranging from 100 to 1230, i know i can do an "IF" and get it to work, but the nest limit of 7 means i would have to go VBA, it also seems rather brutal.

The Vlookup looks neater but always returns the item below the one i want..... there must be away of looking at the cell beneath the cell refered to by the vlookup?


 
Posted : 13/11/2009 10:06 pm
Posts: 0
Free Member
 

Use VLOOKUP(Value,Array,2,True)

and make the array like this:

100 125
125 150
150 175
175 200
200 225

Is that right?


 
Posted : 13/11/2009 10:30 pm
Posts: 0
Free Member
 

You can do more ifs or rather use two or more of 7 if you name them (insert > name > define) and shift + insert to paste them into the reference bit. Then reference them as =IF(formula_a, formula_a, formula_b)

See: http://www.cpearson.com/excel/nested.htm

But you'll need to do the formulas with if ands: =if(and(A1>0, A1<11),10,if(and(A1>10, A1<21,20, etc.


 
Posted : 13/11/2009 11:20 pm
 GJP
Posts: 0
Free Member
 

How about dividing each number in the list by the number in the "box". These will either be less than 1 or greater than one. Then the one you want will be the minimum of the set of those with a ratio > 1.

Thus should be possible with if(), min() and lookup type functions. Will also work even if the list is in a random order rather than ranked.

Edit.

Actually this only needs min and lookup functions and no nasty nested ifs which are a PITA.


 
Posted : 13/11/2009 11:29 pm
Posts: 36
Free Member
 

[s]mrmo, you can use an array formula like this:

array of your list of values is A1:A10

check number is B1

{=MATCH(B1, A1:A8)}

{} means Array formula - when you've typed in =MATCH(B1, A1:A8), then press ctrl+shift+enter and you get the array formula.

it will return the position of your check number in the array, so to bring back the nearest number use:

{=OFFSET($A$1, MATCH(B1, A1:A8), 0, 1, 1)}[/s]

EDIT, by [s]some fluke you dont actually need it to be an array formula.[/s] as you've already found with the vlookup function,
The Match reference will always bring back the closest lowest result in the array, so then all you need is to use the offset function to make it the next highest number in the array:

=OFFSET($A$1, MATCH(B1, A1:A8), 0, 1, 1)


 
Posted : 13/11/2009 11:30 pm