Vba Vlookup to reference range from a file whose name varies

guilhermelemos

New Member
Joined
Oct 7, 2013
Messages
11
Hi,


I'm trying to do a vlooup where the lookup range is on a file whose name varies depending on when the report being run was run the last time.


I've figured out a way to find the appropriate file and open it.


What I haven't found is the right way to do the vlooup, so I get the comments from the previous report instance. I'm getting error 438: "Object doesn't support this property or method".


How do I fix it? Any ideas? This will be placed into a larger code, which already works.


Thanks in advance.

Guil.




Code:








Sub Second_vlookup()


ThisWorkbook.UpdateLinks = xlUpdateLinksNever
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim wrkMyWorkBook As Workbook
Dim x, xlastrow As Integer
Dim alookup, rlookup, slookup, tlookup, ulookup As Variant

Set wrkMyWorkBook = Workbooks.Open(Filename:=Sheets("Sheet1").Range("C3").Value & "" & Sheets("Sheet1").Range("D3").Value)

Workbooks("Quality_release_priorities_20180202.xlsm").Activate

xlastrow = Cells(Rows.Count, "C").End(xlUp).Row

For x = xlastrow To 2 Step -1


'This is the part that doesn't work.
ActiveSheet.Cells(x, 18).Value = _
Application.WorksheetFunction.VLookup(Cells(x, 1), Workbooks(wrkMyWorkBook(Sheets("Release_Priorities"))).Range("A1:U10000"), 18, False)



Next x


End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Code:
On Error Resume Next
ActiveSheet.Cells(x, 18).Value = _
  Application.WorksheetFunction.VLookup(cells(x, 1),[COLOR=#ff0000] wrkMyWorkBook[/COLOR].Sheets("Release_Priorities").Range("A1:U10000"), 18, False)
On Error GoTo 0

rough...?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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