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

nested ifs vba

ResolvedVersion 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:

How to apply the same formatting and data to multiple sheets at the same time in Excel 2010

When you want to format more than one sheet in a worksheet exactly the same way, Ctrl-click the tabs of the sheets you want to group together and they will all turn white. While they are grouped, anything you enter in one sheet gets entered into the others.

After you have done this, remember to click on the tabs to take them out of the group so that you do not accidentally insert data in multiple sheets when you just want to insert data in one.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.