vba vlookup error differente workbook

mlcalves

New Member
Joined
Mar 10, 2021
Messages
47
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
Hi people,

i'm trying do do a vlookup in vba with two differente files, but i get error:

run-time error '1004':

Unable to get the vlookup property of the worksheetfunction class


code:
VBA Code:
Dim x As Integer
Dim procura As String

For x = 6 To 200
WB.Sheets("Ausências Previstas").Range("E" & x) = Application.WorksheetFunction.VLookup(WB.Sheets("Ausências Previstas").Range("B" & x), Presencas.Sheets("1").Range("B27:BF200"), 50, False)

Next


can anyone help me, please?

Thank you, regards
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi,​
enter manually a VLOOKUP formula in cell E6, try the same for cell E7 and once both work as expected,​
share each formula in this thread in order anyone can help without any useless loop …​
 
Upvote 0
Hi,​
enter manually a VLOOKUP formula in cell E6, try the same for cell E7 and once both work as expected,​
share each formula in this thread in order anyone can help without any useless loop …​
Hi: the formula works:

Excel Formula:
=VLOOKUP(B6;'[Presenças_202111.xlsb]1'!$B$27:$BF$191;50;FALSE)
=VLOOKUP(B7;'[Presenças_202111.xlsb]1'!$B$27:$BF$191;50;FALSE)


my vba code is wrong?
 
Upvote 0
So try​
VBA Code:
    With WB.Sheets("Ausências Previstas").Range("E6:E200")
        .Formula = "=VLOOKUP(B6;'[Presenças_202111.xlsb]1'!$B$27:$BF$191;50;FALSE)"
        .Formula = .Value2
    End With
 
Upvote 0
With WB.Sheets("Ausências Previstas").Range("E6:E200") .Formula = "=VLOOKUP(B6;'[Presenças_202111.xlsb]1'!$B$27:$BF$191;50;FALSE)" .Formula = .Value2 End With
i need to user a for, because can be B6 to B200. doesn't work =/
 
Upvote 0

Yes if you need to slow down the execution you can use a loop allocating the formula cell by cell …​
 
Upvote 0
Yes if you need to slow down the execution you can use a loop allocating the formula cell by cell …​
Sorry, but can you explain whats is wrong on this:

VBA Code:
Dim x As Integer
Dim procura As String

For x = 6 To 200
WB.Sheets("Ausências Previstas").Range("E" & x) = Application.WorksheetFunction.VLookup(WB.Sheets("Ausências Previstas").Range("B" & x), Presencas.Sheets("1").Range("B27:BF200"), 50, False)

Next

this code should work, right?

thank you
 
Upvote 0
If it does not work so there is something obviously bad within !​
As you are using WorksheetFunction so the execution obviously crashes if the worksheet function returns any error …​
So try without this statement, just keep Application.​
But as obviously a loop is totally useless except to slow down your code …​
 
Upvote 0
If it does not work so there is something obviously bad within !​
As you are using WorksheetFunction so the execution obviously crashes if the worksheet function returns any error …​
So try without this statement, just keep Application.​
But as obviously a loop is totally useless except to slow down your code …​

this works :)

VBA Code:
For x = 6 To 200


    Dim lookFor As Range
    Dim srchRange As Range
    
    Set lookFor = WB.Sheets("Ausências Previstas").Range("B" & x)
    Set srchRange = Presencas.Sheets("1").Range("B27:BF200")
    
   WB.Sheets("Ausências Previstas").Range("E" & x) = Application.VLookup(lookFor, srchRange, 50, False)


Next
 
Upvote 0
Solution

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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