Nested "If" statements don't always work...

Posted on 2013-02-02
Last Modified: 2013-02-02
I have four columns. In column BD, cells 9-16 have the following data:
"W1", "W1", "W1", "W2", "W2", "W3", "W3", "W4"
In column BE, cells 9-16 have the following data:
"NR", "R1", "R2", "R3", "R4", "R5", "R6", "R7"

You'll notice that W1 corresponds to NR, R1,& R2, W2 corresponds to R3 & R4, W3 corresponds to R5 & R6, and W4 corresponds to R7.

In column AF, cells 9-30 have the following function assigned:


Therefore, each of the cells in AF9:AF30 will read any of "W1", "W2", "W3", or "W4" randomly.

Here is my problem: In AV9:AV30 are supposed to analyze AF9:AF30. If, for example, the cell AF9 reads as "W1", then I want it to randomly fill AV9 with any of "NR", "R1", or "R2" (BE9:BE11).

I am currently just trying to get the formula to work, so in cell AV9 my formula currently reads as the following nested "IF" statement:


It functions only some of the time, and only at specific times. If AV9="W1", then AV9="NR" or "R1" or "R2" randomly. But if AF9="W2" or "W3" or "W4", it reads as an error. I notice the first part of my nested IF statement refers to W1, so I can see the function only looks at the first part. What must be done to correct this?

I am only focusing on the functions of cells AF9 and AV9 right now, I will modify the final function later.
Question by:AlixTech
  • 3
  • 3
LVL 16

Assisted Solution

kmslogic earned 250 total points
ID: 38847752
It seems like what you want is more like this (I think you have some paren problems):

Note you have to scrunch this all back together on one line I have it indented to make the paren matches easier to see:

	AF9="W1", INDEX($BE9:$BE11, RANDBETWEEN(1,COUNTA($BE9:$BE11)),1),

Open in new window

LVL 26

Accepted Solution

redmondb earned 250 total points
ID: 38847785
Hi, AlixTech.

The following is a simpler formula...

Edit: Changed to handle invalid input. This requires Excel 2007 or higher, so please let me know if you're using an earlier version.

Edit2: This handles earlier versions as well...


Author Comment

ID: 38847862
Thanks guys, both of your formulas eliminated the "ERROR". Unfortunately, there's a new problem. "W1", "W2", "W3", and "W4" don't always correspond to ("NR", "R1", "R2"), ("R3", "R4"), ("R5", "R6"), or "R7" respectively. Neither formula acts to account for this even though they seem as if they should. Any thoughts?

I still need:

NR,R1,R2 to randomly be assigned to W1
R3,R4 to randomly be assigned to W2
R5,R6 to randomly be assigned to W3
R7 to randomly be assigned to W4
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

LVL 26

Expert Comment

ID: 38847890

In all my testing the allocations were done as you say - if I've understood you correctly. Please see the attached.


Author Comment

ID: 38847907
Ah, I see. Thanks so much! I accidentally assigned the formula without appropriately modifying it for each cell in list AV9:AV30. Both formulas work perfectly, and now I can design just one formula if I wish. Thanks!!

Author Closing Comment

ID: 38847908
Easy to understand, even for a novice like myself. Both solutions were exactly as I needed, the second was a simpler way to do it that I didn't know before, so now I know two ways to accomplish similar tasks.
LVL 26

Expert Comment

ID: 38847924
Thanks, AlixTech.

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now