[Solved] Check for range?

Discuss the spreadsheet application
Locked
Robindude
Posts: 10
Joined: Sun Oct 06, 2013 11:43 pm

[Solved] Check for range?

Post by Robindude »

I want to check the value of a cell against a range of values. I can do this with nested IF statements (I think, haven't actually tested it yet), but that's so... ugly! I'm hoping for a better method. Currently what I have is this:
IF(I3<V$1;5;IF(I3<W$1;4;IF(I3<X$1;3;IF(I3<Y$1;2;IF(I3<Z$1;1;-10)))))
Effectively this determines which range the value is in (which one it's under first), and then returns the associated value.
Last edited by Robindude on Tue Sep 12, 2017 5:35 am, edited 1 time in total.
Open Office 4.0 on Win 7
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Check for range?

Post by Villeroy »

=LOOKUP(I3 ; $V$1:$AA$2)

with V2:AA2
5 4 3 2 1 -10

This simple formula implies that V1:AA2 is sorted in ascending order and it matches including the threshold values.
IF(I3<=V$1;5;IF(I3<=W$1;4;IF(I3<=X$1;3;IF(I3<=Y$1;2;IF(I3<Z$1;1;-10)))))
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: Check for range?

Post by RusselB »

My first impression is that this seems an ideal situation for one of the LOOKUP functions. MATCH and HLOOKUP (based on the order you presented in code) would be my suggestions to check.
Usage of either one of these functions may require a reorganization of the data on your spreadsheet.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
Robindude
Posts: 10
Joined: Sun Oct 06, 2013 11:43 pm

Re: Check for range?

Post by Robindude »

LOOKUP won't work, since I don't want the values of V1:AA2, I want values 5 to -10 depending on the less-than. :(
That is, V1:AA2 is 5 10 15 26 36

So if I3 is between 10 and 14, the new cell should read 3.
And my idea didn't work for some reason! :(
Open Office 4.0 on Win 7
User avatar
Zizi64
Volunteer
Posts: 11505
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Check for range?

Post by Zizi64 »

LOOKUP won't work, since I don't want the values of V1:AA2, I want values 5 to -10 depending on the less-than. :(
That is, V1:AA2 is 5 10 15 26 36

So if I3 is between 10 and 14, the new cell should read 3.
And my idea didn't work for some reason! :(
Please upload your real, ODF type sample file here.
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Robindude
Posts: 10
Joined: Sun Oct 06, 2013 11:43 pm

Re: Check for range?

Post by Robindude »

File included. The one I'm trying to make better is cell V3. I got is working (with $ symbols before the letters, too). It works, but it's ugly. Part of the reason I want it this way is so I can fiddle with values V2:Z2 and adjust things.
Attachments
DogTime.ods
(34.99 KiB) Downloaded 125 times
Open Office 4.0 on Win 7
User avatar
MrProgrammer
Moderator
Posts: 5431
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Check for range?

Post by MrProgrammer »

Robindude wrote:I got is working (with $ symbols before the letters, too). It works, but it's ugly. Part of the reason I want it this way is so I can fiddle with values V2:Z2 and adjust things.
Compare formulas in B5 and B6. This depends on C2:G2 being in ascending order, as shown by the values in your example.
201709092121.ods
(8.2 KiB) Downloaded 112 times
[Tutorial] VLOOKUP questions and answers

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Locked