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.
[Solved] Check for range?
[Solved] Check for range?
Last edited by Robindude on Tue Sep 12, 2017 5:35 am, edited 1 time in total.
Open Office 4.0 on Win 7
Re: Check for range?
=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)))))
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Check for range?
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.
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.
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.
Re: Check for range?
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!
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
Re: Check for range?
Please upload your real, ODF type sample file here.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!
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.
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.
Re: Check for range?
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
- MrProgrammer
- Moderator
- Posts: 5431
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Check for range?
Compare formulas in B5 and B6. This depends on C2:G2 being in ascending order, as shown by the values in your example. [Tutorial] VLOOKUP questions and answersRobindude 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.
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).
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).