Expanding Nested IF

lisa6538

New Member
Joined
Oct 26, 2016
Messages
3
I have a nested IF statement that I need to expand if a new column is added which happens often. Wondering if there is a better way to handle this?

Here's my formula
=IF($A$4=$D$4,$D7,IF($A$4=$E$4,$E7,IF($A$4=$F$4,$F7)))

If works perfectly, except I will be adding a column G next month and H the following month, etc. I tried to nest an OR in the IF statement which works for the logical test, but not for the value if true.

Any suggestions would be appreciated.

Thank you!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
If the pattern remains the same, here is a formula. It should be entered using Ctrl+Shift+Enter, not just Enter.

=INDEX($D$7:$H$7,MATCH(1,--($D$4:$H$4=$A$4),0))
 
Upvote 0
Hi Lisa,

Welcome to the forums.

Can you please post a sample of your data that way we can see what's going on so we know exactly what it is that you are trying to achieve?

Also, how many columns are you planning on adding, will there be an end to it?

Or maybe what sheetspread was saying...

Code:
=HLOOKUP(A4,$D$4:$XFD$7,4,0)
 
Last edited:
Upvote 0
Hi and welcome to the MrExcel Message Board.

This seems to work: =HLOOKUP(A4,D4:H7,4,0)

It performs a horizontal look up matching A4 with the data in D4:H7. If it finds an exact match it returns the value from the 4th row in the Range i.e. row 7.
Instead of H7 you could specify the end of the Range much farther out e.g. ZZ7. It depends on how far you want to go.

If you want to return FALSE like the nested IFs when the value is not found you could use: =IFERROR(HLOOKUP(A4,D4:ZZ7,4,0),FALSE)



Regards,
 
Upvote 0
Using Excel 2013. The data in columns D-L will change on rows 7-21. There could be more columns based on how many months and years we are reporting on. Here's my spreadsheet. The IF formula is in Column B =IF($A$4=$D$4,$D7,IF($A$4=$E$4,$E7,IF($A$4=$F$4,$F7))). Everything else is static data.



A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
L​
2016
2016
2016
2016
2016
2016
2016
2016
2016
2016
9
9
8
7
6
5
4
3
2
1
2025
2025
2024
2023
2022
2021
2020
2019
2018
2017
Footnote Formula
Line 7
a
a
Line 8
a
Line 9
a
Line 10
b
b
Line 11
Line 12
c
c
Line 13
b
Line 14
b
Line 15
Line 16
Line 17
d
d
Line 18
c
Line 19
c
Line 20
Line 21

<tbody>
</tbody>
 
Upvote 0
I tried the Index Match with the array that Tetra101 suggested and it works. I can't figure out the HLookup though.
 
Upvote 0
I can't test until later, but doesn't =INDEX($D$7:$H$7,MATCH($A$4,$D$4:$H$4,0)) without ctrl-shift-enter or the hlookups that Cyrus and Rick posted have the same effect?
 
Upvote 0
Now I have seen the data, I think the INDEX/MATCH solution will be better.

It looks as if the formula is to be placed in cell B7 and then dragged down.
The HLOOKUP formula would be something like: =HLOOKUP($A$4,$D$4:$ZZ7,ROW(B7)-3,0)

However, that inserts a zero where empty cells are looked up. A workaround will be required for that.


Regards,
 
Upvote 0
... doesn't =INDEX($D$7:$H$7,MATCH($A$4,$D$4:$H$4,0)) without ctrl-shift-enter or the hlookups that Cyrus and Rick posted have the same effect?

They have to.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top