Alternative Dynamic VLookup on VBA

wragostinho

New Member
Joined
May 18, 2018
Messages
3
Hi, I'm trying to write a code to define an alternative VLOOKUP that works with closed files and in a dynamic way.

My problem is, although the code be very simples as you will see, I'm receiving a error message that I not able to solve.

Could someone help me?

--------------------------
Information about code (content of ranges):
Range("B4") = \\SERVER1\ENGINEERING\AREA\TESTS\VEHICLES\RACING\DUR\DAILY\ACTIVE\TEXT_RR.xlsx
$B$6 = 7
------------------------

Sub v_look_up()Dim iRow As Long

teste0 = InStr(1, Range("B4"), ".xlsm")
teste1 = InStr(1, Range("B4"), ".xlsx")
teste2 = InStr(1, Range("B4"), ".xls")
teste3 = InStrRev(Range("B4"), "")

If teste0 <> 0 Then
arquivo = Mid(Range("b4"), InStrRev(Range("B4"), "") + 1, InStr(1, Range("B4"), ".xlsm"))
Else
If teste1 <> 0 Then
arquivo = Mid(Range("b4"), InStrRev(Range("B4"), "") + 1, InStr(1, Range("B4"), ".xlsx"))
Else
If teste2 <> 0 Then
arquivo = Mid(Range("b4"), InStrRev(Range("B4"), "") + 1, InStr(1, Range("B4"), ".xls"))
End If
End If
End If

rangedebusca = "[" & arquivo & "]DAILY'!$A$14:$P$2500"
diretorio = Mid(Range("B4"), 1, InStrRev(Range("B4"), ""))

For iRow = 3 To 25
With Rows(iRow)
.Range("H3:H2503").Formula = "=VLOOKUP(" & .Range("E3").Address(False, True) & ";'" & diretorio & rangedebusca & ";$B$6;FALSE)"
End With
Next iRow

End Sub

-------------------
The error message is:

Run-time error '1004':
Application-defined or object-defined error
-------------------


A important information about the code is, if I copy the results of concatenation in the cell manually, everything works.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Welcome to the Board

What range is supposed to receive the formulas?

"H3:H25" - all rows in this range.

The information on code H2503 was wrong, sorry. I already changed it, I mean from H2503 to H25 and the error continues.

Thank's in advance.
 
Upvote 0
I found the problem.


In this sentence,


"=" VLOOKUP ("& .Range (" E3 "). Address (False, True) &"; '"& directory & rangedearch &"; $ B $ 6; FALSE) "


I needed to replace all semicolon by comma, this way the VBA interpreter understood my code.


In this case I could stay using semicolon but I needed to use .FormulaLocal


Thank you again @Worf to try to help me.


Greetings.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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