Nested IFERROR VLOOKUP macro

pnwAnalyst

New Member
Joined
Oct 30, 2017
Messages
9
New to VBA. I've searched the internet and found a bunch of valuable tips, but I've been working on this all darn day and can't come up with a viable solution.

I'm attempting to semi-automate a process here at work and this is the last segment and I'm stuck. I spent the first half of the morning trying to figure out why it was throwing an error only to find out that IFERROR won't work in a macro. And that I'm supposed to use the WorksheetFunction.

Here is the code that I copied and pasted from another macro that worked, but it was only using a vlookup not iferror.

Code:
Sub AutomateAllTheThings4()
Dim lastRow As Long


    Call OptimizeCode_Begin
        'PO_DETAILS
            Worksheets("PO_DETAILS").Select    
            Range("BE2").Select
            Selection.Formula = "=IFERROR(VLOOKUP($AW2,Full_Item_List!A$2:A$1917,1,0), _
            IFERROR(VLOOKUP($AX2,Full_Item_List!A$2:A$1917,1,0), _
            IFERROR(VLOOKUP($AY2,Full_Item_List!A$2:A$1917,1,0), _
            IFERROR(VLOOKUP($AZ2,Full_Item_List!A$2:A$1917,1,0), _
            IFERROR(VLOOKUP($BA2,Full_Item_List!A$2:A$1917,1,0), _
            IFERROR(VLOOKUP($BB2,Full_Item_List!A$2:A$1917,1,0), _
            IFERROR(VLOOKUP($BC2,Full_Item_List!A$2:A$1917,1,0), _
            IFERROR(VLOOKUP($BD2,Full_Item_List!A$2:A$1917,1,0), ""))))))))"
                'Fills down the formula.  Looks at Column to left to know when to stop filling the formula
                lastRow = Range("BD1:BD" & Range("BD1").End(xlDown).Row).Rows.Count
                Range("BE2" & ":BE" & lastRow).fillDown            
            Range("BF2").Select    
            Selection.Formula = "=IFERROR(VLOOKUP($AW2,Full_Item_List!B$2:B$1917,1,0), _
            IFERROR(VLOOKUP($AX2,Full_Item_List!B$2:B$1917,1,0), _
            IFERROR(VLOOKUP($AY2,Full_Item_List!B$2:B$1917,1,0), _
            IFERROR(VLOOKUP($AZ2,Full_Item_List!B$2:B$1917,1,0), _
            IFERROR(VLOOKUP($BA2,Full_Item_List!B$2:B$1917,1,0), _
            IFERROR(VLOOKUP($BB2,Full_Item_List!B$2:B$1917,1,0), _
            IFERROR(VLOOKUP($BC2,Full_Item_List!B$2:B$1917,1,0), _
            IFERROR(VLOOKUP($BD2,Full_Item_List!B$2:B$1917,1,0), ""))))))))"    
                'Fills down the formula.  Looks at Column to left to know when to stop filling the formula
                lastRow = Range("BD1:BD" & Range("BD1").End(xlDown).Row).Rows.Count
                Range("BF2" & ":BF" & lastRow).fillDown
                
    Call OptimizeCode_End
End Sub

And here is the best example that I found but I couldn't translate it to work for my application.

Code:
Range("D4:D100").Value = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Range("B4:B100"), Sheets("Environmental").Range("A812:J912"), 8, False), _
Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Range("B4:B100"), Sheets("Safety").Range("A812:J912"), 8, False), _
Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Range("B4:B100"), Sheets("Agency").Range("A812:J912"), 8, False), _
Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Range("B4:B100"), Sheets("Endurance").Range("A812:J912"), 8, False), _
Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Range("B4:B100"), Sheets("Performance").Range("A812:J912"), 8, False), _
Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Range("B4:B100"), Sheets("Abuse").Range("A812:J912"), 8, False), _
Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Range("B4:B100"), Sheets("Audit").Range("A812:J912"), 8, False), _ 
Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Range("B4:B100"), Sheets("Other BU").Range("A812:J912"), 8, False), _ 
Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Range("B4:B100"), Sheets("ECO").Range("A812:J912"), 8, False), " ")))))))))
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Update: This fills the column down, but with only the first found value. I feel like I'm close but still have no idea what I'm doing.

Code:
'THIS ALMOST WORKS
				'*******************************************************************************
				Range("BE2").Value = Application.IfError(Application.VLookup(Range("AW2"), Sheets("Full_Item_List").Range("A2:A1917"),1,0), _
				Application.IfError(Application.VLookup(Range("AX2"), Sheets("Full_Item_List").Range("A2:A1917"),1,0), _
				Application.IfError(Application.VLookup(Range("AY2"), Sheets("Full_Item_List").Range("A2:A1917"),1,0), _
				Application.IfError(Application.VLookup(Range("AZ2"), Sheets("Full_Item_List").Range("A2:A1917"),1,0), _
				Application.IfError(Application.VLookup(Range("BA2"), Sheets("Full_Item_List").Range("A2:A1917"),1,0), _
				Application.IfError(Application.VLookup(Range("BB2"), Sheets("Full_Item_List").Range("A2:A1917"),1,0), _
				Application.IfError(Application.VLookup(Range("BC2"), Sheets("Full_Item_List").Range("A2:A1917"),1,0), _
				Application.IfError(Application.VLookup(Range("BD2"), Sheets("Full_Item_List").Range("A2:A1917"),1,0), ""))))))))
				'THIS ALMOST WORKS
				'*******************************************************************************
					'Fills down the formula.  Looks at Column to left to know when to stop filling the formula
					lastRow = Range("BD1:BD" & Range("BD1").End(xlDown).Row).Rows.Count
					Range("BE2" & ":BE" & lastRow).fillDown
 
Upvote 0
This entire process took me 6 hours the first time I did it (manually without any macros). I've set up default columns and sheets so that we could semi-automate it. As we have to do this process for different categories a whole bunch of times during each month.
 
Upvote 0
What exactly do you have in (in your code) row 2, that you are searching for?
If 1 cell has something, will the others be blank?
Maybe explain what you are trying to achieve here?
 
Upvote 0
Columns AW-AZ and BA-BD are the same but with special characters removed in the column BA-BD. I'm grabbing all known product mfg numbers and comparing them across multiple sheets. Its complicated because sometimes the product numbers match, and sometimes they're off by 1 or 2 characters sometimes we don't even have records, which means that the products are new or expiring which in turn means that we have to flag those records.

Here's a snippet of when I use the formula and what it looks like.
https://i.imgur.com/LanElQc.jpg

There's probably a much better or more efficient way of doing this, but this is what I was given, so I'm trying to make the best of it.
 
Upvote 0
I am not permitted to go to file hosting sites :(

can you show a (clean) sample of some of the names, as well as he variations that might be found?
,maybe you missed this Q?
If 1 cell has something, will the others be blank?
 
Upvote 0
Here's what I was trying to post...

[TABLE="width: 750"]
<tbody>[TR]
[TD="class: xl68, width: 75"]Facility Manufacturer Catalog Num[/TD]
[TD="class: xl68, width: 75"]Facility Vendor Catalog Num[/TD]
[TD="class: xl68, width: 75"]Manufacturer Catalog Number[/TD]
[TD="class: xl68, width: 75"]Contracted Catalog Number[/TD]
[TD="class: xl68, width: 75"]Facility Manufacturer Catalog Num[/TD]
[TD="class: xl68, width: 75"]Facility Vendor Catalog Num[/TD]
[TD="class: xl68, width: 75"]Manufacturer Catalog Number[/TD]
[TD="class: xl68, width: 75"]Contracted Catalog Number[/TD]
[TD="class: xl67, width: 75"]Match 1[/TD]
[TD="class: xl67, width: 75"]Match 2[/TD]
[/TR]
[TR]
[TD="class: xl65"]81801[/TD]
[TD="class: xl65"]81801[/TD]
[TD="class: xl65"]81801[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl65"]81801[/TD]
[TD="class: xl65"]81801[/TD]
[TD="class: xl65"]81801[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl66"]81801[/TD]
[TD="class: xl66"][/TD]
[/TR]
[TR]
[TD="class: xl65"]407200[/TD]
[TD="class: xl65"]407200[/TD]
[TD="class: xl65"]407200[/TD]
[TD="class: xl65"]407200[/TD]
[TD="class: xl65"]407200[/TD]
[TD="class: xl65"]407200[/TD]
[TD="class: xl65"]407200[/TD]
[TD="class: xl65"]407200[/TD]
[TD="class: xl66"]407200[/TD]
[TD="class: xl66"][/TD]
[/TR]
[TR]
[TD="class: xl65"]IBI-81104[/TD]
[TD="class: xl65"]IBI-81104[/TD]
[TD="class: xl65"]81104[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl65"]IBI81104[/TD]
[TD="class: xl65"]IBI81104[/TD]
[TD="class: xl65"]81104[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl66"]81104[/TD]
[TD="class: xl66"][/TD]
[/TR]
[TR]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl66"]408310[/TD]
[TD="class: xl66"][/TD]
[/TR]
[TR]
[TD="class: xl65"]100003331[/TD]
[TD="class: xl65"]100003331[/TD]
[TD="class: xl65"]100003331[/TD]
[TD="class: xl65"]100003331[/TD]
[TD="class: xl65"]100003331[/TD]
[TD="class: xl65"]100003331[/TD]
[TD="class: xl65"]100003331[/TD]
[TD="class: xl65"]100003331[/TD]
[TD="class: xl66"][/TD]
[TD="class: xl66"][/TD]
[/TR]
[TR]
[TD="class: xl65"]406898[/TD]
[TD="class: xl65"]406898[/TD]
[TD="class: xl65"]406898[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl65"]406898[/TD]
[TD="class: xl65"]406898[/TD]
[TD="class: xl65"]406898[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl66"]406898[/TD]
[TD="class: xl66"][/TD]
[/TR]
[TR]
[TD="class: xl65"]PN-004 075[/TD]
[TD="class: xl65"]PN-004-075[/TD]
[TD="class: xl65"]PN-004075[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl65"]PN004075[/TD]
[TD="class: xl65"]PN004075[/TD]
[TD="class: xl65"]PN004075[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl66"]PN-004 075[/TD]
[TD="class: xl66"]PN004075[/TD]
[/TR]
[TR]
[TD="class: xl65"]2AF284[/TD]
[TD="class: xl65"]2AF284[/TD]
[TD="class: xl65"]2AF284[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl65"]2AF284[/TD]
[TD="class: xl65"]2AF284[/TD]
[TD="class: xl65"]2AF284[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl66"]2AF284[/TD]
[TD="class: xl66"]2AF284[/TD]
[/TR]
[TR]
[TD="class: xl65"]990063-020[/TD]
[TD="class: xl65"]990063-020[/TD]
[TD="class: xl65"]990063-020[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl65"]990063020[/TD]
[TD="class: xl65"]990063020[/TD]
[TD="class: xl65"]990063020[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl66"][/TD]
[TD="class: xl66"][/TD]
[/TR]
[TR]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl65"]408310[/TD]
[TD="class: xl66"][/TD]
[TD="class: xl66"][/TD]
[/TR]
[TR]
[TD="class: xl65"]PN-004-075[/TD]
[TD="class: xl65"]PN-004 075[/TD]
[TD="class: xl65"]PN-004075[/TD]
[TD="class: xl65"]PN-004 075[/TD]
[TD="class: xl65"]PN004075[/TD]
[TD="class: xl65"]PN004075[/TD]
[TD="class: xl65"]PN004075[/TD]
[TD="class: xl65"]PN004075[/TD]
[TD="class: xl66"][/TD]
[TD="class: xl66"][/TD]
[/TR]
[TR]
[TD="class: xl65"]DYNJ30927[/TD]
[TD="class: xl65"]4552NJ30927G[/TD]
[TD="class: xl65"]DYNJ30927D[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl65"]DYNJ30927[/TD]
[TD="class: xl65"]4552NJ30927G[/TD]
[TD="class: xl65"]DYNJ30927D[/TD]
[TD="class: xl65"]Unknown[/TD]
[TD="class: xl66"][/TD]
[TD="class: xl66"][/TD]
[/TR]
</tbody>[/TABLE]

The only time column BE or BF (Match 1 Match 2) will be blank is when there isn't a corresponding match from the other sheet that I'm referencing. And the reason why there are two different Match columns is because I'm trying to match against all possible scenarios. Usually the only difference is special characters or spaces, but sometimes, like the last row in my C&P the product number is very different.

Apologies if my explanations aren't the best. I was just thrust into doing this last week and am trying to wrap my head around what they're doing as well.
 
Upvote 0

Forum statistics

Threads
1,225,375
Messages
6,184,613
Members
453,247
Latest member
scouterjames

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