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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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
 
Upvote 0
"=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!
 
Upvote 0
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
 
Upvote 0
that's excellent Tom - I had never seen Case used before - and have learnt something new!

Cheers!

Luke
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,019
Members
449,280
Latest member
Miahr

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