VBA VLookUp to another workbook

gustavor0

New Member
Joined
Jul 16, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi! I have two spreadsheets (A and B) and I'd like VBA to do a VLOOKUP from A to B.

Once the ranges are dynamic, I defined counters and they are working, I checked that.

So there's the loop, contador stands for the counter in spreadsheet A. It should look for the content of cell Y&counter in spreadsheet B, from A1 to Cells( counter3, 4) and return me the fourth column match back in spreadsheet A, cell R&counter. Unfortunatelly it displays error message 1004 "definition of application or object definition error".

VBA Code:
Do While contador < Linhas2 + 1

ActiveSheet.Range("R" & contador).Value = Application.VLookup(Range("Y" & contador), Workbooks("ME2M - FUP Atual.mhtml").Sheets("Sheet1").Range(Cells(1, 1), Cells(Linhas, 4)), 4)

contador = contador + 1

Loop

I tried using both Application.WorksheetFunction.Vlookup [...] and just Application.Vlookup [...], same error. The fourth argument of VLOOKUP being true, false or absent, same error.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,225,743
Messages
6,186,777
Members
453,370
Latest member
juliewar

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