1. ## Nested If statements

I have a spreadsheet that I use the following formula in cell A1.

=IF(B1=1,COUNTIF(C1:C5,"X"),IF(B1=2,COUNTIF(C1:C10 ,"X"),IF(B1=3,COUNTIF(C1:C15,"X"),IF(B1=4,COUNTIF( C1:C20,"X")))))

The formula uses the value in B1 to determine the range to count "X"s in column C. The formula works but I will need to continue to expand the ranges over time. There must be another way other than nested IFs but I can't find it. I cannot use a macro due to restrictions placed by our IT dept at work.

Any help would be most appreciated.

Thx
Nicole

2. Nicole,

You could use the following formula:

=COUNTIF(CHOOSE(B1,C1:C5,C1:C10,C1:C15,C1:C20),"X" )

Choose1.png

HTH,
Maud

3. ## The Following User Says Thank You to Maudibe For This Useful Post:

Nicole545 (2014-11-16)

4. Nichole,

If you only have X or blank in col C you could simplify Maud's formula to:
Code:
`=COUNTA(CHOOSE(B1,C1:C5,C1:C10,C1:C15,C1:C20))`
Another approach would be to use a lookup table (can be in current sheet or another sheet) just give it a range name.
Nicole1.JPG
Then use:
Code:
`=COUNTA(INDIRECT(VLOOKUP(\$B\$1,CountRng,2)))`
This makes it easy to add ranges by just expanding your table making sure the Range Name changes to take in the new entries, this can be handled using a DynamicRange Name, e.g.
Code:
`=OFFSET(Sheet2!\$A\$2,0,0,COUNTA(Sheet2!\$A\$2:\$A\$10002),2)`
the above would go into the Refers to: box of the Range Name if your table was on Sheet2.

Another method (if the added ranges keep going up by 5 rows each)
This method requires a "helper cell"
Code:
```Cell    Formula
A1     =COUNTA(INDIRECT(\$A\$2))
A2     =CONCATENATE("C1:C",B1*5)```
Note: Either of the above 2 methods can be changed to use Maud's CountIF should your col C contain other than just X and blank!

Test File: Nichole.xlsx
HTH

5. ## The Following User Says Thank You to RetiredGeek For This Useful Post:

Nicole545 (2014-11-16)

6. Thank you both for helping me to resolve my problem. The values in column C cam be either Xs or free text values but are never blank. What makes it difficult is that even though the ranges will expand over time, I am not using the entire range. At any point, I may need to refer to only a portion based on the value of B1. The Countif/Choose is a nice solution and will be easy to update.

Hat's off to Maud and RG! Thank you so much!
Nicole

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•