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