Vlookup Referencing a Dynamic Workbook Returns Error 438

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I'm trying to get a VLOOKUP to work, but I keep getting a 438 error code. I have other VLOOKUPs that work just fine, but they aren't referencing a dynamic named workbook. I've mimiced what I've seen online, and I'm still getting the error.

VBA Code:
Sub AddMgrName()

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Dim m As Workbook, s As Workbook
Dim mS As Worksheet
Dim mSLR As Long

Set m = ThisWorkbook
Set mS = m.Sheets("SLA")

mSLR = mS.Range("A" & Rows.Count).End(xlUp).Row

With Application.FileDialog(3)
    .AllowMultiSelect = False
    If .Show Then
        fullpath = .SelectedItems.Item(1)
        Set s = Workbooks.Open(fullpath)
    End If
    
    If s Is Nothing Then Exit Sub

End With

mS.Range("U2:U" & mSLR).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-17]," & "'[" & s & "]SBS'!C[-15]:C[-10],6,FALSE),"""")"

'mS.Range("U2:U" & mSLR).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-17]," & "'[" & s & "]SBS'!C6:C11,6,FALSE),""Review"")"
    
'Macro Recorder Gave Me This            "=IFERROR(VLOOKUP(RC[-17],'[SBS Contact List 2023.05.24 v1.xlsx]SBS'!C6:C11,6,FALSE),""Review"")"

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try adding the red text in this line

Rich (BB code):
mS.Range("U2:U" & mSLR).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-17]," & "'[" & s.Name & "]SBS'!C[-15]:C[-10],6,FALSE),"""")"
 
Upvote 0
Solution
Try adding the red text in this line

Rich (BB code):
mS.Range("U2:U" & mSLR).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-17]," & "'[" & s.Name & "]SBS'!C[-15]:C[-10],6,FALSE),"""")"
@Peter_SSs this works like a charm. If you would, help me understand what the .Name addition actually does
 
Upvote 0
Good news! Thanks for letting us know.


It puts the name of the other workbook in the square brackets, just as you would if you were entering the formula manually.
Gotcha! I hadn't come across that before. Thank you!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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