Nested IF statements.

JayLee

Board Regular
Joined
Sep 23, 2002
Messages
52
I have a lot of nested if statements in one cell. Unfortunately, I couldn't add anymore because I believe I hit the limit for the IF statements. Is there another alternative so I may fit more IF-like statements into the cell? Perhaps using the case statement? A formula or VBA code would be helpful. Thanks!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
You'll need to paste some data (or just give an example) and your current formula (with the 7 IFs)

Then we can write some code...

Cheers
Luke
 

JayLee

Board Regular
Joined
Sep 23, 2002
Messages
52
"=IF(RC[-7]=""Cancel Sale "",""SL"",IF(RC[-7]=""Sold "", ""sl"", IF(RC[-7]=""Delivered "", ""sl"", IF(RC[-7]=""Received "", ""by"", IF(RC[-7]=""Purchased "", ""by"", IF(RC[-7]=""Reinvest "", ""by"",IF(RC[-7]=""Dividend "", ""dv"","""")))))))"

There's the nested if in VBA code. I hope to be able to add some more. Thanks!
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,257
You'll need to adjust the following code to fit the environment of your existing macro, but here might be one way to transform your nested If statements to a Select Case structure:

Sub FromIfToSelectCase()
Select Case ActiveCell.Offset(0, -7).Value
Case "Cancel Sale"
ActiveCell.Value = "SL"
Case "Sold", "Delivered"
ActiveCell.Value = "sl"
Case "Received", "Purchased", "Reinvest"
ActiveCell.Value = "by"
Case "Dividend"
ActiveCell.Value = "dv"
Case Else
ActiveCell.Value = ""
End Select
End Sub
 

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
that's excellent Tom - I had never seen Case used before - and have learnt something new!

Cheers!

Luke
 

Forum statistics

Threads
1,144,116
Messages
5,722,568
Members
422,447
Latest member
srclife

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
Top