98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Nested IFs in VBA
Nested IFs in VBA
Resolved · 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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Showing all menu itemsIf 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. |