nested ifs vba

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Nested IFs in VBA

Nested IFs in VBA

resolvedResolved · High Priority · Version 2010

Freddie has attended:
Excel VBA Introduction course

Nested IFs in VBA

Hi Guys

I'm trying to create a nested IF and have the below but it seems to be failing.

I'm trying to Vlookup (with iferror) in a cell to the left for various words e.g. Shadow, MFE etc and if they are there then to have "INLBAMKTCF Exception" or if they aren't there to have "Error"


Sheets("LBAPARIF").Select
Range("Q2").Select
Do Until ActiveCell.Offset(0, -1) = ""
ActiveCell.FormulaR1C1 = "=iferror(VLOOKUP(RC[-1],LBAMKTCF!C[-11]:C[-10],2,0),if(count(SEARCH(""*LME*"",RC[-1]))>0,""INLBAMKTCF - EXCEPTION"",if(count(SEARCH(""*MFE*"",RC[-1]))>0,""INLBAMKTCF - EXCEPTION"",if(count(SEARCH(""*SHADOW*"",RC[-1]))>0,""INLBAMKTCF - EXCEPTION"",if(count(SEARCH(""*ICE*"",RC[-1]))>0,""INLBAMKTCF - EXCEPTION"",""ERROR"""
ActiveCell.Offset(1, 0).Select
Loop

Please advise!

Many thanks
Freddie

RE: Nested IFs in VBA

Hi Freddie,

Thank you for the forum question.

I can see what you want to do.

I have created my own sheet where I try to do the same ting and to me it worked fine. Please have a look at the code below. This should guide you in the right direction.

Range("B2").Select
Do Until ActiveCell.Offset(0, -1).Value = ""

ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC[-1],R2C8:R3C9,2,0),IF(OR(ISNUMBER(SEARCH(""de"",RC[-1])),ISNUMBER(SEARCH(""nc"",RC[-1]))),""is in string"",""error""))"

ActiveCell.Offset(1, 0).Select


Loop

I just recorded it and the added the loop afterwards. Please let me know if it is not what you want.

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Showing all menu items

If you go into a pull down menu you usally find that you get a selection of items(this is the default) or sometimes everything. If you only get a selectiopn you have to go to the double arrows at the bottom of the menu and click it to get all of the hidden items.
To turn this off so that you always get everything, go to Tools / Customize / Options Tab / "Always show full menus". Make sure there is a tick in the box and you will always have every item.

View all Excel hints and tips


Server loaded in 0.08 secs.