Thanks, so what would you suggest for a macro ?
data may not be sorted from small to large.
Main Topics
Browse All Topicsdata set:
0.5, 1.5, 2.1, 0.43, 0.35
my condition number : 1
Result i want the formula to tell me:
number nearest to 1 = 0.5
note: Although 1.5 is also near to 1 (also a 0.5 difference), it must choose the smaller number.
(0.5 is smaller as compared to 1.5)
How can i do this in excel ?
if then else, it is too long winded
max and min doesn't use the condition , min will give 0.35 instead of 0.5 as it compares the set of data and not the set of data against 1.
i was thinking if there is any short cut instead of using programming.
any good idea?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This code would do it, for the spreadsheet you've provided.
Note that if you have more than 25 columns in your source data, this code won't work because it calculates column names based on just A through Z. It also puts the result into the column after the data, however big that is.
If you were to convert this to rows within one column, it would remove that restriction.
Note that I have constants defined at the top of the code where your data size and your condition number can be specified. It wouldn't be terribly difficult to have those be dynamically determined (reading from cells in the spreadsheet, for example).
Let me know if you have any questions.
-- b.r.t.
there are 37 columns. However the range starts from Column Y to Column AE.
I have modified your script as now i want to choose the max of the different.
I managed to get my desired result - see attached for details.
however, i need many corresponding desired results as there are several rows of data.
The data runs in many rows. Thus, can calculate one whole worksheet full of data ?
Sorry for the delay. It's been a busy day today.
This code is working for me. It starts by going to the bottom row in the spreadsheet, and then runs the macro for every line from 2 to that line. If you don't want that many lines to run, you may need to make some changes to that.
This code also assumes that you will have fewer than 27 columns of data, and that your data will start in column Y. You'll need to tweak the code if either of those conditions changes.
Other than those limitations, it seems to work just fine.
-- b.r.t.
If there are more than 27 columns of data, then the column after AZ is going to be improperly identified as A[, which doesn't exist.
I've generalized the code some more to what's below. I haven't tested it, but believe it's right :-)
Note that the previous limit of 27 was for the range of what was actually being looked into for the right value, not for all the other stuff in columns A through X.
-- b.r.t.
Ok , a continuation of this question : just a short one
1. if i want to choose a bigger number, what should i do ?
ie. if 0.75 and 1.25 , they are both 0.25 away from 1.
but i would like to choose the bigger number instead. ie. 1.25.
2. and once 1.25 is chosen , the result will show 1.25 and then inserted a column beside "Result"
and it shows the column header of where 1.25 is from.
for eg. the column title of 1.25 is BOX1. so it should show:
1.25 BOX1
if this needs more points, i will allocate acordingly
thanks!
Business Accounts
Answer for Membership
by: BarryTicePosted on 2008-09-09 at 14:40:08ID: 22432590
You have this in a VB programming category, but say you'd rather not use programming. That reduces options somewhat.
You could set up a column that takes the absolute value of the difference between your condition number (1) and your data, and then for any value in your data lower than your condition number, subtract, say, .000001 to make it minutely smaller than the difference for a number larger than your condition number, determine the minimum from that collection and reference back for your data value.
e.g.:
=ABS(1 - A1) - IF(A1 < 1, .0001, 0)
Will your data always be sorted small to large? It's not in the sample data given. If it were, you could use Match with 1 as the match_type to find the largest value under or equal, and then collect the next value in the list as well, and then you've got a fairly simple if-else to determine which of the two of them is closer.
If you're willing to use a macro to do this, you've got a lot of options. Probably the easiest is to build an array of difference values, and then find the minimum absolute value in that list. The VB code for that would be pretty easy, and could certainly be provided if that would work for you.
-- b.r.t.