Hi,
I'm struggling to find the way in how to use xlookup function, to obtain data from another workbook, but without using the workbook name/path.
I want to avoid using the name of the workbook and the path, because its going to be changing each day both name and location, earlier in the macro i am actually opening the file manually by selecting it with a pop up box, and name it WB2. Having eventually both main file, and the one just opened.
Below code I am using:
After opening the workbook from where i want to obtain the data I name it WB2.
then in the main file where i want to bring the data i do as below:
*LastRow was defined earlier in the macro.
The idea I would like, is to change FileNameWithDataIWant.xlsx into WB2... but I am not sure how to make the change.. :D
Not sure if its possible thou..
Also, for some reason when I try this manually, I am getting in some cells number 0 result, even thou its an empty cell in the original file.. does it make sense?
Lookup is done in order to transfer some comments from a file, to a new one, so not all rows will have data.
Thanks in advance!
Regards,
Dani
I'm struggling to find the way in how to use xlookup function, to obtain data from another workbook, but without using the workbook name/path.
I want to avoid using the name of the workbook and the path, because its going to be changing each day both name and location, earlier in the macro i am actually opening the file manually by selecting it with a pop up box, and name it WB2. Having eventually both main file, and the one just opened.
Below code I am using:
After opening the workbook from where i want to obtain the data I name it WB2.
VBA Code:
Set WB2 = ActiveWorkbook
then in the main file where i want to bring the data i do as below:
VBA Code:
Range("AD2").Select
ActiveCell.FormulaR1C1 = _
"=XLOOKUP(RC[-29],'[FileNameWithDataIWant.xlsx]Sheet1'!$A:$A,'[FileNameWithDataIWant.xlsx.xlsx]Sheet1'!$T:$T," ")"
Range("AD2").Select
Selection.AutoFill Destination:=Range("AD2:AD" & LastRow)
*LastRow was defined earlier in the macro.
The idea I would like, is to change FileNameWithDataIWant.xlsx into WB2... but I am not sure how to make the change.. :D
Not sure if its possible thou..
Also, for some reason when I try this manually, I am getting in some cells number 0 result, even thou its an empty cell in the original file.. does it make sense?
Lookup is done in order to transfer some comments from a file, to a new one, so not all rows will have data.
Thanks in advance!
Regards,
Dani