[Solved] Help with IF THEN OR Statement in Calc

Discuss the spreadsheet application
Locked
bradyso
Posts: 19
Joined: Wed Mar 06, 2013 4:36 am

[Solved] Help with IF THEN OR Statement in Calc

Post by bradyso »

I need a functional formula for OpenOffice Calc that will function like this...

if N3 = "Optics" then "Tactical" or if N3 = "Flashlight" then "Matches"

Basically I need multiple if then statements in one cell so that it can return multiple potential results based on whatever word is placed in there. I spent 2 hours looking but found nothing.

Please please help!
Last edited by bradyso on Thu Mar 07, 2013 7:57 am, edited 1 time in total.
OpenOffice 3.4.1 on Windows 7
FJCC
Moderator
Posts: 9652
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Please Help with IF THEN OR Statement in Calc?

Post by FJCC »

I wouldn't us an If Then formula. Try a VLOOKUP(). For the example you give you would need to use two columns in any convenient spot on your sheet. Let's say columns Y and Z. In Y1 write Optics, in Z1 Tactical, in Y2 Flashlight and in Z2 Matches. You formula would then be

Code: Select all

=VLOOKUP(N3;Y1:Z2;2;0)
It will look in cells Y1 and Y2 for an exact match to the contents of N3 and return the corresponding value in column Z. You can see that this can be expanded to many matched pairs easily, while nested IF() statements become unwieldy very quickly.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
bradyso
Posts: 19
Joined: Wed Mar 06, 2013 4:36 am

Re: Please Help with IF THEN OR Statement in Calc?

Post by bradyso »

Oh ok, that seems to work pretty well so far. But what do I do if the list is really long? For instance in your scenario, I need to put 50 items in column Y, and get a different return for their counterpart to the right in column Z?
OpenOffice 3.4.1 on Windows 7
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Please Help with IF THEN OR Statement in Calc?

Post by acknak »

Sorry, I'm not seeing the problem there.

VLOOKUP will handle hundreds of items in the table; it's much simpler than a single formula with hundreds of IF statements, no?
AOO4/LO5 • Linux • Fedora 23
bradyso
Posts: 19
Joined: Wed Mar 06, 2013 4:36 am

Re: Please Help with IF THEN OR Statement in Calc?

Post by bradyso »

Yes you're right it most certainly is. But when I put something in N23 for instance, can Vlookup reference the list in column Y and insert the corresponding word to the right in column Z and place it in column O?

For instance, I want to paste a massive list into column N, and Vlookup looks for a match anywhere in column Y, and finds the correct counterpart in column Z and pastes it in column O.

Right now when I do that, it just says #N/A. I don't think I did a good job of describing what I'm trying to do...
OpenOffice 3.4.1 on Windows 7
User avatar
MrProgrammer
Moderator
Posts: 5477
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Please Help with IF THEN OR Statement in Calc?

Post by MrProgrammer »

Hi, and welcome to the forum.
bradyso wrote:I need multiple if then statements …
IF() is a function, not a statement. There are no statements in spreadsheet formulas.
bradyso wrote:But when I put something in N23 for instance, can Vlookup reference the list in column Y and insert the corresponding word to the right in column Z and place it in column O?
Yes, that's exactly what VLOOKUP does when you use it in column O.
bradyso wrote:Right now when I do that, it just says #N/A.
[Tutorial] VLOOKUP questions and answers
Read the entire tutorial, but for unexpected #N/A, see Q5, Q6, Q11, Q13, Q14, Q16, Q17, and especially Q19.

If this answered your question 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.
Last edited by MrProgrammer on Wed Mar 06, 2013 10:32 pm, edited 3 times in total.
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).
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Please Help with IF THEN OR Statement in Calc?

Post by Villeroy »

Put this into a cell, say X3: =VLOOKUP($N3;$Y$1:$Z$2;2;0)
Copy the cell.
Select the target range, say X4:X9999
Paste.
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
bradyso
Posts: 19
Joined: Wed Mar 06, 2013 4:36 am

Re: Please Help with IF THEN OR Statement in Calc?

Post by bradyso »

Solved, thanks guys I appreciate it.
OpenOffice 3.4.1 on Windows 7
Locked