Hey guys, I'm new here, I just looked over the whole internet and can't manage to understand what I'm going to explain and that probably is very simple.
So, I have 4 variables:
file1 = Sheets("BD MXN").Range("Y2")
file2 = Sheets("BD MXN").Range("Y3")
sheet1 = Sheets("BD MXN").Range("X4")
sheet2 = Sheets("BD MXN").Range("X5")
These variables are set on a specific cell because they change every month, so basically, before running the macro the user need to change some other cells to get to those variables (which are the file and sheet name of 2 different excel workbooks)
Those variables won't change in the whole code, therefore, I want to insert them into a vlookup or [Index, Match (Inverse vlookup)] formula, for example (name of path is only to make it shorter):
Range("K2").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX('C:\fullpath\[file1]sheet1'!R2C5:R30000C5,MATCH(RC[-9],'C:\fullpath\[file1]sheet1'!R2C6:R30000C6,0)),0)"
So, I tried different syntax to make Excel write whatever it is filled on the variable, however, it writes literally the name of the variable or returns an error instead.
Can someone help me figuring out this one? And an additional and great help would be if someone can explain me the logic on it (not just the code, but to understand what does VBA need to recognize a variable inserted in that way).
Thank you very much in advance.
Bookmarks